@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * permet de specifier le nom du fichier local (stockage d'un cache par exemple, et non document IMG) |
| 65 | 65 | * @param int $taille_max |
| 66 | 66 | * taille maxi de la copie local, par defaut _COPIE_LOCALE_MAX_SIZE |
| 67 | - * @return bool|string |
|
| 67 | + * @return string|false |
|
| 68 | 68 | */ |
| 69 | 69 | function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) { |
| 70 | 70 | |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * La fonction PHP idn_to_ascii depend d'un package php5-intl et est rarement disponible |
| 247 | 247 | * |
| 248 | 248 | * @param string $url_idn |
| 249 | - * @return array|string |
|
| 249 | + * @return string|boolean |
|
| 250 | 250 | */ |
| 251 | 251 | function url_to_ascii($url_idn) { |
| 252 | 252 | |
@@ -642,13 +642,13 @@ discard block |
||
| 642 | 642 | * |
| 643 | 643 | * @param string $url |
| 644 | 644 | * URL de la page à récupérer |
| 645 | - * @param bool|null|string $trans |
|
| 645 | + * @param boolean $trans |
|
| 646 | 646 | * - chaîne longue : c'est un nom de fichier (nom pour sa copie locale) |
| 647 | 647 | * - true : demande d'encodage/charset |
| 648 | 648 | * - null : ne retourner que les headers |
| 649 | 649 | * @param string $get |
| 650 | 650 | * Type de requête HTTP à faire (HEAD, GET ou POST) |
| 651 | - * @param int|bool $taille_max |
|
| 651 | + * @param integer $taille_max |
|
| 652 | 652 | * Arrêter le contenu au-delà (0 = seulement les entetes ==> requête HEAD). |
| 653 | 653 | * Par defaut taille_max = 1Mo. |
| 654 | 654 | * @param string|array $datas |
@@ -774,7 +774,7 @@ discard block |
||
| 774 | 774 | * |
| 775 | 775 | * @param resource $handle |
| 776 | 776 | * @param int|bool $if_modified_since |
| 777 | - * @return bool|array |
|
| 777 | + * @return string |
|
| 778 | 778 | * int status |
| 779 | 779 | * string headers |
| 780 | 780 | * int last_modified |
@@ -1251,9 +1251,9 @@ discard block |
||
| 1251 | 1251 | * donnees postees |
| 1252 | 1252 | * @param string $vers |
| 1253 | 1253 | * version HTTP |
| 1254 | - * @param int|string $date |
|
| 1254 | + * @param string $date |
|
| 1255 | 1255 | * timestamp pour entente If-Modified-Since |
| 1256 | - * @return bool|resource |
|
| 1256 | + * @return string |
|
| 1257 | 1257 | * false|int si echec |
| 1258 | 1258 | * resource socket vers l'url demandee |
| 1259 | 1259 | */ |
@@ -1256,8 +1256,9 @@ |
||
| 1256 | 1256 | $http_noproxy = " $http_noproxy "; |
| 1257 | 1257 | $domain = $host; |
| 1258 | 1258 | // si le domaine exact www.example.org est dans les exceptions |
| 1259 | - if (strpos($http_noproxy, " $domain ") !== false) |
|
| 1260 | - return ''; |
|
| 1259 | + if (strpos($http_noproxy, " $domain ") !== false) { |
|
| 1260 | + return ''; |
|
| 1261 | + } |
|
| 1261 | 1262 | |
| 1262 | 1263 | while (strpos($domain, '.') !== false) { |
| 1263 | 1264 | $domain = explode('.', $domain); |
@@ -16,32 +16,32 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Distant |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
| 23 | - define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 23 | + define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 24 | 24 | } |
| 25 | 25 | if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
| 26 | - define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 26 | + define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | - define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 32 | + define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 33 | 33 | } |
| 34 | 34 | if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
| 35 | - define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 35 | + define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 39 | - preg_replace( |
|
| 40 | - '@^https?:@', |
|
| 41 | - 'https?:', |
|
| 42 | - (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | - ) |
|
| 44 | - . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 39 | + preg_replace( |
|
| 40 | + '@^https?:@', |
|
| 41 | + 'https?:', |
|
| 42 | + (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | + ) |
|
| 44 | + . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 45 | 45 | |
| 46 | 46 | //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait) |
| 47 | 47 | |
@@ -68,77 +68,77 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) { |
| 70 | 70 | |
| 71 | - // si c'est la protection de soi-meme, retourner le path |
|
| 72 | - if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | - |
|
| 75 | - return @file_exists($source) ? $source : false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (is_null($local)) { |
|
| 79 | - $local = fichier_copie_locale($source); |
|
| 80 | - } else { |
|
| 81 | - if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | - $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | - // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | - // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | - if (!$local) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 94 | - $t = ($mode == 'force') ? false : @file_exists($localrac); |
|
| 95 | - |
|
| 96 | - // test d'existence du fichier |
|
| 97 | - if ($mode == 'test') { |
|
| 98 | - return $t ? $local : ''; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // sinon voir si on doit/peut le telecharger |
|
| 102 | - if ($local == $source or !tester_url_absolue($source)) { |
|
| 103 | - return $local; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($mode == 'modif' or !$t) { |
|
| 107 | - // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | - // et des eventuelles recuperations concurantes |
|
| 109 | - include_spip('inc/acces'); |
|
| 110 | - if (!$taille_max) { |
|
| 111 | - $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | - } |
|
| 113 | - $res = recuperer_url( |
|
| 114 | - $source, |
|
| 115 | - array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '') |
|
| 116 | - ); |
|
| 117 | - if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], _LOG_INFO_IMPORTANTE); |
|
| 119 | - } |
|
| 120 | - if (!$res['length']) { |
|
| 121 | - // si $t c'est sans doute juste un not-modified-since |
|
| 122 | - return $t ? $local : false; |
|
| 123 | - } |
|
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK'); |
|
| 125 | - |
|
| 126 | - // pour une eventuelle indexation |
|
| 127 | - pipeline( |
|
| 128 | - 'post_edition', |
|
| 129 | - array( |
|
| 130 | - 'args' => array( |
|
| 131 | - 'operation' => 'copie_locale', |
|
| 132 | - 'source' => $source, |
|
| 133 | - 'fichier' => $local, |
|
| 134 | - 'http_res' => $res['length'], |
|
| 135 | - ), |
|
| 136 | - 'data' => null |
|
| 137 | - ) |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $local; |
|
| 71 | + // si c'est la protection de soi-meme, retourner le path |
|
| 72 | + if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | + |
|
| 75 | + return @file_exists($source) ? $source : false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (is_null($local)) { |
|
| 79 | + $local = fichier_copie_locale($source); |
|
| 80 | + } else { |
|
| 81 | + if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | + $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | + // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | + // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | + if (!$local) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $localrac = _DIR_RACINE . $local; |
|
| 94 | + $t = ($mode == 'force') ? false : @file_exists($localrac); |
|
| 95 | + |
|
| 96 | + // test d'existence du fichier |
|
| 97 | + if ($mode == 'test') { |
|
| 98 | + return $t ? $local : ''; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // sinon voir si on doit/peut le telecharger |
|
| 102 | + if ($local == $source or !tester_url_absolue($source)) { |
|
| 103 | + return $local; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($mode == 'modif' or !$t) { |
|
| 107 | + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | + // et des eventuelles recuperations concurantes |
|
| 109 | + include_spip('inc/acces'); |
|
| 110 | + if (!$taille_max) { |
|
| 111 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | + } |
|
| 113 | + $res = recuperer_url( |
|
| 114 | + $source, |
|
| 115 | + array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '') |
|
| 116 | + ); |
|
| 117 | + if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], _LOG_INFO_IMPORTANTE); |
|
| 119 | + } |
|
| 120 | + if (!$res['length']) { |
|
| 121 | + // si $t c'est sans doute juste un not-modified-since |
|
| 122 | + return $t ? $local : false; |
|
| 123 | + } |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK'); |
|
| 125 | + |
|
| 126 | + // pour une eventuelle indexation |
|
| 127 | + pipeline( |
|
| 128 | + 'post_edition', |
|
| 129 | + array( |
|
| 130 | + 'args' => array( |
|
| 131 | + 'operation' => 'copie_locale', |
|
| 132 | + 'source' => $source, |
|
| 133 | + 'fichier' => $local, |
|
| 134 | + 'http_res' => $res['length'], |
|
| 135 | + ), |
|
| 136 | + 'data' => null |
|
| 137 | + ) |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $local; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -153,88 +153,88 @@ discard block |
||
| 153 | 153 | * url ou false en cas d'echec |
| 154 | 154 | */ |
| 155 | 155 | function valider_url_distante($url, $known_hosts = array()) { |
| 156 | - if (!function_exists('protocole_verifier')){ |
|
| 157 | - include_spip('inc/filtres_mini'); |
|
| 158 | - } |
|
| 156 | + if (!function_exists('protocole_verifier')){ |
|
| 157 | + include_spip('inc/filtres_mini'); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - if (!protocole_verifier($url, array('http', 'https'))) { |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 160 | + if (!protocole_verifier($url, array('http', 'https'))) { |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - $parsed_url = parse_url($url); |
|
| 165 | - if (!$parsed_url or empty($parsed_url['host']) ) { |
|
| 166 | - return false; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 170 | - return false; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - if (!is_array($known_hosts)) { |
|
| 178 | - $known_hosts = array($known_hosts); |
|
| 179 | - } |
|
| 180 | - $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 181 | - $known_hosts[] = url_de_base(); |
|
| 182 | - $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 183 | - |
|
| 184 | - $is_known_host = false; |
|
| 185 | - foreach ($known_hosts as $known_host) { |
|
| 186 | - $parse_known = parse_url($known_host); |
|
| 187 | - if ($parse_known |
|
| 188 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) { |
|
| 189 | - $is_known_host = true; |
|
| 190 | - break; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if (!$is_known_host) { |
|
| 195 | - $host = trim($parsed_url['host'], '.'); |
|
| 196 | - if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) { |
|
| 197 | - $ip = $host; |
|
| 198 | - } else { |
|
| 199 | - $ip = gethostbyname($host); |
|
| 200 | - if ($ip === $host) { |
|
| 201 | - // Error condition for gethostbyname() |
|
| 202 | - $ip = false; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - if ($ip) { |
|
| 206 | - $parts = array_map('intval', explode( '.', $ip )); |
|
| 207 | - if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
|
| 208 | - or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 209 | - or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 210 | - ) { |
|
| 211 | - return false; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (empty($parsed_url['port'])) { |
|
| 217 | - return $url; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - $port = $parsed_url['port']; |
|
| 221 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 222 | - return $url; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - if ($is_known_host) { |
|
| 226 | - foreach ($known_hosts as $known_host) { |
|
| 227 | - $parse_known = parse_url($known_host); |
|
| 228 | - if ($parse_known |
|
| 229 | - and !empty($parse_known['port']) |
|
| 230 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 231 | - and $parse_known['port'] == $port) { |
|
| 232 | - return $url; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - return false; |
|
| 164 | + $parsed_url = parse_url($url); |
|
| 165 | + if (!$parsed_url or empty($parsed_url['host']) ) { |
|
| 166 | + return false; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 170 | + return false; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + if (!is_array($known_hosts)) { |
|
| 178 | + $known_hosts = array($known_hosts); |
|
| 179 | + } |
|
| 180 | + $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 181 | + $known_hosts[] = url_de_base(); |
|
| 182 | + $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 183 | + |
|
| 184 | + $is_known_host = false; |
|
| 185 | + foreach ($known_hosts as $known_host) { |
|
| 186 | + $parse_known = parse_url($known_host); |
|
| 187 | + if ($parse_known |
|
| 188 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host'])) { |
|
| 189 | + $is_known_host = true; |
|
| 190 | + break; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if (!$is_known_host) { |
|
| 195 | + $host = trim($parsed_url['host'], '.'); |
|
| 196 | + if (preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host)) { |
|
| 197 | + $ip = $host; |
|
| 198 | + } else { |
|
| 199 | + $ip = gethostbyname($host); |
|
| 200 | + if ($ip === $host) { |
|
| 201 | + // Error condition for gethostbyname() |
|
| 202 | + $ip = false; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + if ($ip) { |
|
| 206 | + $parts = array_map('intval', explode( '.', $ip )); |
|
| 207 | + if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
|
| 208 | + or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 209 | + or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 210 | + ) { |
|
| 211 | + return false; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (empty($parsed_url['port'])) { |
|
| 217 | + return $url; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + $port = $parsed_url['port']; |
|
| 221 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 222 | + return $url; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + if ($is_known_host) { |
|
| 226 | + foreach ($known_hosts as $known_host) { |
|
| 227 | + $parse_known = parse_url($known_host); |
|
| 228 | + if ($parse_known |
|
| 229 | + and !empty($parse_known['port']) |
|
| 230 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 231 | + and $parse_known['port'] == $port) { |
|
| 232 | + return $url; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + return false; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -253,86 +253,86 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | function prepare_donnees_post($donnees, $boundary = '') { |
| 255 | 255 | |
| 256 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 257 | - // pour un appel soap par exemple |
|
| 258 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 259 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 260 | - if (is_string($donnees) && strlen($donnees)) { |
|
| 261 | - $entete = ''; |
|
| 262 | - // on repasse tous les \r\n et \r en simples \n |
|
| 263 | - $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 264 | - $donnees = str_replace("\r", "\n", $donnees); |
|
| 265 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 266 | - $p = strpos($donnees, "\n\n"); |
|
| 267 | - if ($p !== false) { |
|
| 268 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 269 | - $donnees = substr($donnees, $p + 2); |
|
| 270 | - } |
|
| 271 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 272 | - } else { |
|
| 273 | - /* boundary automatique */ |
|
| 274 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 275 | - if ($boundary === '') { |
|
| 276 | - $taille = 0; |
|
| 277 | - foreach ($donnees as $cle => $valeur) { |
|
| 278 | - if (is_array($valeur)) { |
|
| 279 | - foreach ($valeur as $val2) { |
|
| 280 | - $taille += strlen($val2); |
|
| 281 | - } |
|
| 282 | - } else { |
|
| 283 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 284 | - $taille += strlen($valeur); |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - if ($taille > 500) { |
|
| 288 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if (is_string($boundary) and strlen($boundary)) { |
|
| 293 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 294 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 295 | - $chaine = ''; |
|
| 296 | - if (is_array($donnees)) { |
|
| 297 | - foreach ($donnees as $cle => $valeur) { |
|
| 298 | - if (is_array($valeur)) { |
|
| 299 | - foreach ($valeur as $val2) { |
|
| 300 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 301 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 302 | - $chaine .= "\r\n"; |
|
| 303 | - $chaine .= $val2; |
|
| 304 | - } |
|
| 305 | - } else { |
|
| 306 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 307 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 308 | - $chaine .= "\r\n"; |
|
| 309 | - $chaine .= $valeur; |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 313 | - } |
|
| 314 | - } else { |
|
| 315 | - // fabrique une chaine HTTP simple pour un POST |
|
| 316 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 317 | - $chaine = array(); |
|
| 318 | - if (is_array($donnees)) { |
|
| 319 | - foreach ($donnees as $cle => $valeur) { |
|
| 320 | - if (is_array($valeur)) { |
|
| 321 | - foreach ($valeur as $val2) { |
|
| 322 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 323 | - } |
|
| 324 | - } else { |
|
| 325 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - $chaine = implode('&', $chaine); |
|
| 329 | - } else { |
|
| 330 | - $chaine = $donnees; |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - return array($entete, $chaine); |
|
| 256 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 257 | + // pour un appel soap par exemple |
|
| 258 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 259 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 260 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 261 | + $entete = ''; |
|
| 262 | + // on repasse tous les \r\n et \r en simples \n |
|
| 263 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 264 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 265 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 266 | + $p = strpos($donnees, "\n\n"); |
|
| 267 | + if ($p !== false) { |
|
| 268 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 269 | + $donnees = substr($donnees, $p + 2); |
|
| 270 | + } |
|
| 271 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 272 | + } else { |
|
| 273 | + /* boundary automatique */ |
|
| 274 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 275 | + if ($boundary === '') { |
|
| 276 | + $taille = 0; |
|
| 277 | + foreach ($donnees as $cle => $valeur) { |
|
| 278 | + if (is_array($valeur)) { |
|
| 279 | + foreach ($valeur as $val2) { |
|
| 280 | + $taille += strlen($val2); |
|
| 281 | + } |
|
| 282 | + } else { |
|
| 283 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 284 | + $taille += strlen($valeur); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + if ($taille > 500) { |
|
| 288 | + $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if (is_string($boundary) and strlen($boundary)) { |
|
| 293 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 294 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 295 | + $chaine = ''; |
|
| 296 | + if (is_array($donnees)) { |
|
| 297 | + foreach ($donnees as $cle => $valeur) { |
|
| 298 | + if (is_array($valeur)) { |
|
| 299 | + foreach ($valeur as $val2) { |
|
| 300 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 301 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 302 | + $chaine .= "\r\n"; |
|
| 303 | + $chaine .= $val2; |
|
| 304 | + } |
|
| 305 | + } else { |
|
| 306 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 307 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 308 | + $chaine .= "\r\n"; |
|
| 309 | + $chaine .= $valeur; |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 313 | + } |
|
| 314 | + } else { |
|
| 315 | + // fabrique une chaine HTTP simple pour un POST |
|
| 316 | + $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 317 | + $chaine = array(); |
|
| 318 | + if (is_array($donnees)) { |
|
| 319 | + foreach ($donnees as $cle => $valeur) { |
|
| 320 | + if (is_array($valeur)) { |
|
| 321 | + foreach ($valeur as $val2) { |
|
| 322 | + $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 323 | + } |
|
| 324 | + } else { |
|
| 325 | + $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + $chaine = implode('&', $chaine); |
|
| 329 | + } else { |
|
| 330 | + $chaine = $donnees; |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + return array($entete, $chaine); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | /** |
@@ -346,18 +346,18 @@ discard block |
||
| 346 | 346 | */ |
| 347 | 347 | function url_to_ascii($url_idn) { |
| 348 | 348 | |
| 349 | - if ($parts = parse_url($url_idn)) { |
|
| 350 | - $host = $parts['host']; |
|
| 351 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 352 | - include_spip('inc/idna_convert.class'); |
|
| 353 | - $IDN = new idna_convert(); |
|
| 354 | - $host_ascii = $IDN->encode($host); |
|
| 355 | - $url_idn = explode($host, $url_idn, 2); |
|
| 356 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - return $url_idn; |
|
| 349 | + if ($parts = parse_url($url_idn)) { |
|
| 350 | + $host = $parts['host']; |
|
| 351 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 352 | + include_spip('inc/idna_convert.class'); |
|
| 353 | + $IDN = new idna_convert(); |
|
| 354 | + $host_ascii = $IDN->encode($host); |
|
| 355 | + $url_idn = explode($host, $url_idn, 2); |
|
| 356 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + return $url_idn; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -396,172 +396,172 @@ discard block |
||
| 396 | 396 | * string file : nom du fichier si enregistre dans un fichier |
| 397 | 397 | */ |
| 398 | 398 | function recuperer_url($url, $options = array()) { |
| 399 | - $default = array( |
|
| 400 | - 'transcoder' => false, |
|
| 401 | - 'methode' => 'GET', |
|
| 402 | - 'taille_max' => null, |
|
| 403 | - 'datas' => '', |
|
| 404 | - 'boundary' => '', |
|
| 405 | - 'refuser_gz' => false, |
|
| 406 | - 'if_modified_since' => '', |
|
| 407 | - 'uri_referer' => '', |
|
| 408 | - 'file' => '', |
|
| 409 | - 'follow_location' => 10, |
|
| 410 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 411 | - ); |
|
| 412 | - $options = array_merge($default, $options); |
|
| 413 | - // copier directement dans un fichier ? |
|
| 414 | - $copy = $options['file']; |
|
| 415 | - |
|
| 416 | - if ($options['methode'] == 'HEAD') { |
|
| 417 | - $options['taille_max'] = 0; |
|
| 418 | - } |
|
| 419 | - if (is_null($options['taille_max'])) { |
|
| 420 | - $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if (!empty($options['datas'])) { |
|
| 424 | - list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 425 | - if (stripos($head, 'Content-Length:') === false) { |
|
| 426 | - $head .= 'Content-Length: ' . strlen($postdata); |
|
| 427 | - } |
|
| 428 | - $options['datas'] = $head . "\r\n\r\n" . $postdata; |
|
| 429 | - if (strlen($postdata)) { |
|
| 430 | - $options['methode'] = 'POST'; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 435 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 436 | - if (!tester_url_absolue($url)) { |
|
| 437 | - $url = 'http://' . $url; |
|
| 438 | - } elseif (strncmp($url, '//', 2) == 0) { |
|
| 439 | - $url = 'http:' . $url; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - $url = url_to_ascii($url); |
|
| 443 | - |
|
| 444 | - $result = array( |
|
| 445 | - 'status' => 0, |
|
| 446 | - 'headers' => '', |
|
| 447 | - 'page' => '', |
|
| 448 | - 'length' => 0, |
|
| 449 | - 'last_modified' => '', |
|
| 450 | - 'location' => '', |
|
| 451 | - 'url' => $url |
|
| 452 | - ); |
|
| 453 | - |
|
| 454 | - // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 455 | - $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 456 | - |
|
| 457 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 458 | - list($handle, $fopen) = init_http( |
|
| 459 | - $options['methode'], |
|
| 460 | - $url, |
|
| 461 | - $refuser_gz, |
|
| 462 | - $options['uri_referer'], |
|
| 463 | - $options['datas'], |
|
| 464 | - $options['version_http'], |
|
| 465 | - $options['if_modified_since'] |
|
| 466 | - ); |
|
| 467 | - if (!$handle) { |
|
| 468 | - spip_log("ECHEC init_http $url"); |
|
| 469 | - |
|
| 470 | - return false; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 474 | - // et recuperer les en-tetes de reponses |
|
| 475 | - if (!$fopen) { |
|
| 476 | - $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 477 | - if (!$res) { |
|
| 478 | - fclose($handle); |
|
| 479 | - $t = @parse_url($url); |
|
| 480 | - $host = $t['host']; |
|
| 481 | - // Chinoisierie inexplicable pour contrer |
|
| 482 | - // les actions liberticides de l'empire du milieu |
|
| 483 | - if (!need_proxy($host) |
|
| 484 | - and $res = @file_get_contents($url) |
|
| 485 | - ) { |
|
| 486 | - $result['length'] = strlen($res); |
|
| 487 | - if ($copy) { |
|
| 488 | - ecrire_fichier($copy, $res); |
|
| 489 | - $result['file'] = $copy; |
|
| 490 | - } else { |
|
| 491 | - $result['page'] = $res; |
|
| 492 | - } |
|
| 493 | - $res = array( |
|
| 494 | - 'status' => 200, |
|
| 495 | - ); |
|
| 496 | - } else { |
|
| 497 | - return false; |
|
| 498 | - } |
|
| 499 | - } elseif ($res['location'] and $options['follow_location']) { |
|
| 500 | - $options['follow_location']--; |
|
| 501 | - fclose($handle); |
|
| 502 | - include_spip('inc/filtres'); |
|
| 503 | - $url = suivre_lien($url, $res['location']); |
|
| 504 | - spip_log("recuperer_url recommence sur $url"); |
|
| 505 | - |
|
| 506 | - return recuperer_url($url, $options); |
|
| 507 | - } elseif ($res['status'] !== 200) { |
|
| 508 | - spip_log('HTTP status ' . $res['status'] . " pour $url"); |
|
| 509 | - } |
|
| 510 | - $result['status'] = $res['status']; |
|
| 511 | - if (isset($res['headers'])) { |
|
| 512 | - $result['headers'] = $res['headers']; |
|
| 513 | - } |
|
| 514 | - if (isset($res['last_modified'])) { |
|
| 515 | - $result['last_modified'] = $res['last_modified']; |
|
| 516 | - } |
|
| 517 | - if (isset($res['location'])) { |
|
| 518 | - $result['location'] = $res['location']; |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - // on ne veut que les entetes |
|
| 523 | - if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 524 | - return $result; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 529 | - // sinon la memoire explose pour les gros flux |
|
| 530 | - |
|
| 531 | - $gz = false; |
|
| 532 | - if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 533 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - // si on a pas deja recuperer le contenu par une methode detournee |
|
| 537 | - if (!$result['length']) { |
|
| 538 | - $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 539 | - fclose($handle); |
|
| 540 | - if ($copy) { |
|
| 541 | - $result['length'] = $res; |
|
| 542 | - $result['file'] = $copy; |
|
| 543 | - } elseif ($res) { |
|
| 544 | - $result['page'] = &$res; |
|
| 545 | - $result['length'] = strlen($result['page']); |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - if (!$result['page']) { |
|
| 549 | - return $result; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - // Decompresser au besoin |
|
| 553 | - if ($gz) { |
|
| 554 | - $result['page'] = implode('', gzfile($gz)); |
|
| 555 | - supprimer_fichier($gz); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - // Faut-il l'importer dans notre charset local ? |
|
| 559 | - if ($options['transcoder']) { |
|
| 560 | - include_spip('inc/charsets'); |
|
| 561 | - $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - return $result; |
|
| 399 | + $default = array( |
|
| 400 | + 'transcoder' => false, |
|
| 401 | + 'methode' => 'GET', |
|
| 402 | + 'taille_max' => null, |
|
| 403 | + 'datas' => '', |
|
| 404 | + 'boundary' => '', |
|
| 405 | + 'refuser_gz' => false, |
|
| 406 | + 'if_modified_since' => '', |
|
| 407 | + 'uri_referer' => '', |
|
| 408 | + 'file' => '', |
|
| 409 | + 'follow_location' => 10, |
|
| 410 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 411 | + ); |
|
| 412 | + $options = array_merge($default, $options); |
|
| 413 | + // copier directement dans un fichier ? |
|
| 414 | + $copy = $options['file']; |
|
| 415 | + |
|
| 416 | + if ($options['methode'] == 'HEAD') { |
|
| 417 | + $options['taille_max'] = 0; |
|
| 418 | + } |
|
| 419 | + if (is_null($options['taille_max'])) { |
|
| 420 | + $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if (!empty($options['datas'])) { |
|
| 424 | + list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 425 | + if (stripos($head, 'Content-Length:') === false) { |
|
| 426 | + $head .= 'Content-Length: ' . strlen($postdata); |
|
| 427 | + } |
|
| 428 | + $options['datas'] = $head . "\r\n\r\n" . $postdata; |
|
| 429 | + if (strlen($postdata)) { |
|
| 430 | + $options['methode'] = 'POST'; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 435 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 436 | + if (!tester_url_absolue($url)) { |
|
| 437 | + $url = 'http://' . $url; |
|
| 438 | + } elseif (strncmp($url, '//', 2) == 0) { |
|
| 439 | + $url = 'http:' . $url; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + $url = url_to_ascii($url); |
|
| 443 | + |
|
| 444 | + $result = array( |
|
| 445 | + 'status' => 0, |
|
| 446 | + 'headers' => '', |
|
| 447 | + 'page' => '', |
|
| 448 | + 'length' => 0, |
|
| 449 | + 'last_modified' => '', |
|
| 450 | + 'location' => '', |
|
| 451 | + 'url' => $url |
|
| 452 | + ); |
|
| 453 | + |
|
| 454 | + // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 455 | + $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 456 | + |
|
| 457 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 458 | + list($handle, $fopen) = init_http( |
|
| 459 | + $options['methode'], |
|
| 460 | + $url, |
|
| 461 | + $refuser_gz, |
|
| 462 | + $options['uri_referer'], |
|
| 463 | + $options['datas'], |
|
| 464 | + $options['version_http'], |
|
| 465 | + $options['if_modified_since'] |
|
| 466 | + ); |
|
| 467 | + if (!$handle) { |
|
| 468 | + spip_log("ECHEC init_http $url"); |
|
| 469 | + |
|
| 470 | + return false; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 474 | + // et recuperer les en-tetes de reponses |
|
| 475 | + if (!$fopen) { |
|
| 476 | + $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 477 | + if (!$res) { |
|
| 478 | + fclose($handle); |
|
| 479 | + $t = @parse_url($url); |
|
| 480 | + $host = $t['host']; |
|
| 481 | + // Chinoisierie inexplicable pour contrer |
|
| 482 | + // les actions liberticides de l'empire du milieu |
|
| 483 | + if (!need_proxy($host) |
|
| 484 | + and $res = @file_get_contents($url) |
|
| 485 | + ) { |
|
| 486 | + $result['length'] = strlen($res); |
|
| 487 | + if ($copy) { |
|
| 488 | + ecrire_fichier($copy, $res); |
|
| 489 | + $result['file'] = $copy; |
|
| 490 | + } else { |
|
| 491 | + $result['page'] = $res; |
|
| 492 | + } |
|
| 493 | + $res = array( |
|
| 494 | + 'status' => 200, |
|
| 495 | + ); |
|
| 496 | + } else { |
|
| 497 | + return false; |
|
| 498 | + } |
|
| 499 | + } elseif ($res['location'] and $options['follow_location']) { |
|
| 500 | + $options['follow_location']--; |
|
| 501 | + fclose($handle); |
|
| 502 | + include_spip('inc/filtres'); |
|
| 503 | + $url = suivre_lien($url, $res['location']); |
|
| 504 | + spip_log("recuperer_url recommence sur $url"); |
|
| 505 | + |
|
| 506 | + return recuperer_url($url, $options); |
|
| 507 | + } elseif ($res['status'] !== 200) { |
|
| 508 | + spip_log('HTTP status ' . $res['status'] . " pour $url"); |
|
| 509 | + } |
|
| 510 | + $result['status'] = $res['status']; |
|
| 511 | + if (isset($res['headers'])) { |
|
| 512 | + $result['headers'] = $res['headers']; |
|
| 513 | + } |
|
| 514 | + if (isset($res['last_modified'])) { |
|
| 515 | + $result['last_modified'] = $res['last_modified']; |
|
| 516 | + } |
|
| 517 | + if (isset($res['location'])) { |
|
| 518 | + $result['location'] = $res['location']; |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + // on ne veut que les entetes |
|
| 523 | + if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 524 | + return $result; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 529 | + // sinon la memoire explose pour les gros flux |
|
| 530 | + |
|
| 531 | + $gz = false; |
|
| 532 | + if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 533 | + $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + // si on a pas deja recuperer le contenu par une methode detournee |
|
| 537 | + if (!$result['length']) { |
|
| 538 | + $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 539 | + fclose($handle); |
|
| 540 | + if ($copy) { |
|
| 541 | + $result['length'] = $res; |
|
| 542 | + $result['file'] = $copy; |
|
| 543 | + } elseif ($res) { |
|
| 544 | + $result['page'] = &$res; |
|
| 545 | + $result['length'] = strlen($result['page']); |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + if (!$result['page']) { |
|
| 549 | + return $result; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + // Decompresser au besoin |
|
| 553 | + if ($gz) { |
|
| 554 | + $result['page'] = implode('', gzfile($gz)); |
|
| 555 | + supprimer_fichier($gz); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + // Faut-il l'importer dans notre charset local ? |
|
| 559 | + if ($options['transcoder']) { |
|
| 560 | + include_spip('inc/charsets'); |
|
| 561 | + $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + return $result; |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
@@ -577,72 +577,72 @@ discard block |
||
| 577 | 577 | * @return array|bool|mixed |
| 578 | 578 | */ |
| 579 | 579 | function recuperer_url_cache($url, $options = array()) { |
| 580 | - if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 581 | - define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 582 | - } |
|
| 583 | - $default = array( |
|
| 584 | - 'transcoder' => false, |
|
| 585 | - 'methode' => 'GET', |
|
| 586 | - 'taille_max' => null, |
|
| 587 | - 'datas' => '', |
|
| 588 | - 'boundary' => '', |
|
| 589 | - 'refuser_gz' => false, |
|
| 590 | - 'if_modified_since' => '', |
|
| 591 | - 'uri_referer' => '', |
|
| 592 | - 'file' => '', |
|
| 593 | - 'follow_location' => 10, |
|
| 594 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 595 | - 'delai_cache' => _DELAI_RECUPERER_URL_CACHE, |
|
| 596 | - ); |
|
| 597 | - $options = array_merge($default, $options); |
|
| 598 | - |
|
| 599 | - // cas ou il n'est pas possible de cacher |
|
| 600 | - if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 601 | - return recuperer_url($url, $options); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 605 | - static $errors = array(); |
|
| 606 | - if (isset($errors[$url])) { |
|
| 607 | - return $errors[$url]; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - $sig = $options; |
|
| 611 | - unset($sig['if_modified_since']); |
|
| 612 | - unset($sig['delai_cache']); |
|
| 613 | - $sig['url'] = $url; |
|
| 614 | - |
|
| 615 | - $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 616 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 617 | - $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 618 | - $cache = "$sub$cache"; |
|
| 619 | - |
|
| 620 | - $res = false; |
|
| 621 | - $is_cached = file_exists($cache); |
|
| 622 | - if ($is_cached |
|
| 623 | - and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 624 | - ) { |
|
| 625 | - lire_fichier($cache, $res); |
|
| 626 | - if ($res = unserialize($res)) { |
|
| 627 | - // mettre le last_modified et le status=304 ? |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - if (!$res) { |
|
| 631 | - $res = recuperer_url($url, $options); |
|
| 632 | - // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 633 | - if (!$res) { |
|
| 634 | - if ($is_cached) { |
|
| 635 | - // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 636 | - lire_fichier($cache, $res); |
|
| 637 | - $res = unserialize($res); |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - return $errors[$url] = $res; |
|
| 641 | - } |
|
| 642 | - ecrire_fichier($cache, serialize($res)); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - return $res; |
|
| 580 | + if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 581 | + define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 582 | + } |
|
| 583 | + $default = array( |
|
| 584 | + 'transcoder' => false, |
|
| 585 | + 'methode' => 'GET', |
|
| 586 | + 'taille_max' => null, |
|
| 587 | + 'datas' => '', |
|
| 588 | + 'boundary' => '', |
|
| 589 | + 'refuser_gz' => false, |
|
| 590 | + 'if_modified_since' => '', |
|
| 591 | + 'uri_referer' => '', |
|
| 592 | + 'file' => '', |
|
| 593 | + 'follow_location' => 10, |
|
| 594 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 595 | + 'delai_cache' => _DELAI_RECUPERER_URL_CACHE, |
|
| 596 | + ); |
|
| 597 | + $options = array_merge($default, $options); |
|
| 598 | + |
|
| 599 | + // cas ou il n'est pas possible de cacher |
|
| 600 | + if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 601 | + return recuperer_url($url, $options); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 605 | + static $errors = array(); |
|
| 606 | + if (isset($errors[$url])) { |
|
| 607 | + return $errors[$url]; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + $sig = $options; |
|
| 611 | + unset($sig['if_modified_since']); |
|
| 612 | + unset($sig['delai_cache']); |
|
| 613 | + $sig['url'] = $url; |
|
| 614 | + |
|
| 615 | + $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 616 | + $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 617 | + $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 618 | + $cache = "$sub$cache"; |
|
| 619 | + |
|
| 620 | + $res = false; |
|
| 621 | + $is_cached = file_exists($cache); |
|
| 622 | + if ($is_cached |
|
| 623 | + and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 624 | + ) { |
|
| 625 | + lire_fichier($cache, $res); |
|
| 626 | + if ($res = unserialize($res)) { |
|
| 627 | + // mettre le last_modified et le status=304 ? |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + if (!$res) { |
|
| 631 | + $res = recuperer_url($url, $options); |
|
| 632 | + // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 633 | + if (!$res) { |
|
| 634 | + if ($is_cached) { |
|
| 635 | + // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 636 | + lire_fichier($cache, $res); |
|
| 637 | + $res = unserialize($res); |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + return $errors[$url] = $res; |
|
| 641 | + } |
|
| 642 | + ecrire_fichier($cache, serialize($res)); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + return $res; |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | /** |
@@ -680,52 +680,52 @@ discard block |
||
| 680 | 680 | * - false si la page n'a pu être récupérée (status different de 200) |
| 681 | 681 | **/ |
| 682 | 682 | function recuperer_page( |
| 683 | - $url, |
|
| 684 | - $trans = false, |
|
| 685 | - $get_headers = false, |
|
| 686 | - $taille_max = null, |
|
| 687 | - $datas = '', |
|
| 688 | - $boundary = '', |
|
| 689 | - $refuser_gz = false, |
|
| 690 | - $date_verif = '', |
|
| 691 | - $uri_referer = '' |
|
| 683 | + $url, |
|
| 684 | + $trans = false, |
|
| 685 | + $get_headers = false, |
|
| 686 | + $taille_max = null, |
|
| 687 | + $datas = '', |
|
| 688 | + $boundary = '', |
|
| 689 | + $refuser_gz = false, |
|
| 690 | + $date_verif = '', |
|
| 691 | + $uri_referer = '' |
|
| 692 | 692 | ) { |
| 693 | - // $copy = copier le fichier ? |
|
| 694 | - $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-) |
|
| 695 | - |
|
| 696 | - if (!is_null($taille_max) and ($taille_max == 0)) { |
|
| 697 | - $get = 'HEAD'; |
|
| 698 | - } else { |
|
| 699 | - $get = 'GET'; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - $options = array( |
|
| 703 | - 'transcoder' => $trans === true, |
|
| 704 | - 'methode' => $get, |
|
| 705 | - 'datas' => $datas, |
|
| 706 | - 'boundary' => $boundary, |
|
| 707 | - 'refuser_gz' => $refuser_gz, |
|
| 708 | - 'if_modified_since' => $date_verif, |
|
| 709 | - 'uri_referer' => $uri_referer, |
|
| 710 | - 'file' => $copy ? $trans : '', |
|
| 711 | - 'follow_location' => 10, |
|
| 712 | - ); |
|
| 713 | - if (!is_null($taille_max)) { |
|
| 714 | - $options['taille_max'] = $taille_max; |
|
| 715 | - } |
|
| 716 | - // dix tentatives maximum en cas d'entetes 301... |
|
| 717 | - $res = recuperer_url($url, $options); |
|
| 718 | - if (!$res) { |
|
| 719 | - return false; |
|
| 720 | - } |
|
| 721 | - if ($res['status'] !== 200) { |
|
| 722 | - return false; |
|
| 723 | - } |
|
| 724 | - if ($get_headers) { |
|
| 725 | - return $res['headers'] . "\n" . $res['page']; |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - return $res['page']; |
|
| 693 | + // $copy = copier le fichier ? |
|
| 694 | + $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-) |
|
| 695 | + |
|
| 696 | + if (!is_null($taille_max) and ($taille_max == 0)) { |
|
| 697 | + $get = 'HEAD'; |
|
| 698 | + } else { |
|
| 699 | + $get = 'GET'; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + $options = array( |
|
| 703 | + 'transcoder' => $trans === true, |
|
| 704 | + 'methode' => $get, |
|
| 705 | + 'datas' => $datas, |
|
| 706 | + 'boundary' => $boundary, |
|
| 707 | + 'refuser_gz' => $refuser_gz, |
|
| 708 | + 'if_modified_since' => $date_verif, |
|
| 709 | + 'uri_referer' => $uri_referer, |
|
| 710 | + 'file' => $copy ? $trans : '', |
|
| 711 | + 'follow_location' => 10, |
|
| 712 | + ); |
|
| 713 | + if (!is_null($taille_max)) { |
|
| 714 | + $options['taille_max'] = $taille_max; |
|
| 715 | + } |
|
| 716 | + // dix tentatives maximum en cas d'entetes 301... |
|
| 717 | + $res = recuperer_url($url, $options); |
|
| 718 | + if (!$res) { |
|
| 719 | + return false; |
|
| 720 | + } |
|
| 721 | + if ($res['status'] !== 200) { |
|
| 722 | + return false; |
|
| 723 | + } |
|
| 724 | + if ($get_headers) { |
|
| 725 | + return $res['headers'] . "\n" . $res['page']; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + return $res['page']; |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | |
@@ -762,48 +762,48 @@ discard block |
||
| 762 | 762 | * - false sinon |
| 763 | 763 | **/ |
| 764 | 764 | function recuperer_lapage( |
| 765 | - $url, |
|
| 766 | - $trans = false, |
|
| 767 | - $get = 'GET', |
|
| 768 | - $taille_max = 1048576, |
|
| 769 | - $datas = '', |
|
| 770 | - $refuser_gz = false, |
|
| 771 | - $date_verif = '', |
|
| 772 | - $uri_referer = '' |
|
| 765 | + $url, |
|
| 766 | + $trans = false, |
|
| 767 | + $get = 'GET', |
|
| 768 | + $taille_max = 1048576, |
|
| 769 | + $datas = '', |
|
| 770 | + $refuser_gz = false, |
|
| 771 | + $date_verif = '', |
|
| 772 | + $uri_referer = '' |
|
| 773 | 773 | ) { |
| 774 | - // $copy = copier le fichier ? |
|
| 775 | - $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-) |
|
| 776 | - |
|
| 777 | - // si on ecrit directement dans un fichier, pour ne pas manipuler |
|
| 778 | - // en memoire refuser gz |
|
| 779 | - if ($copy) { |
|
| 780 | - $refuser_gz = true; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - $options = array( |
|
| 784 | - 'transcoder' => $trans === true, |
|
| 785 | - 'methode' => $get, |
|
| 786 | - 'datas' => $datas, |
|
| 787 | - 'refuser_gz' => $refuser_gz, |
|
| 788 | - 'if_modified_since' => $date_verif, |
|
| 789 | - 'uri_referer' => $uri_referer, |
|
| 790 | - 'file' => $copy ? $trans : '', |
|
| 791 | - 'follow_location' => false, |
|
| 792 | - ); |
|
| 793 | - if (!is_null($taille_max)) { |
|
| 794 | - $options['taille_max'] = $taille_max; |
|
| 795 | - } |
|
| 796 | - // dix tentatives maximum en cas d'entetes 301... |
|
| 797 | - $res = recuperer_url($url, $options); |
|
| 798 | - |
|
| 799 | - if (!$res) { |
|
| 800 | - return false; |
|
| 801 | - } |
|
| 802 | - if ($res['status'] !== 200) { |
|
| 803 | - return false; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - return array($res['headers'], $res['page']); |
|
| 774 | + // $copy = copier le fichier ? |
|
| 775 | + $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-) |
|
| 776 | + |
|
| 777 | + // si on ecrit directement dans un fichier, pour ne pas manipuler |
|
| 778 | + // en memoire refuser gz |
|
| 779 | + if ($copy) { |
|
| 780 | + $refuser_gz = true; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + $options = array( |
|
| 784 | + 'transcoder' => $trans === true, |
|
| 785 | + 'methode' => $get, |
|
| 786 | + 'datas' => $datas, |
|
| 787 | + 'refuser_gz' => $refuser_gz, |
|
| 788 | + 'if_modified_since' => $date_verif, |
|
| 789 | + 'uri_referer' => $uri_referer, |
|
| 790 | + 'file' => $copy ? $trans : '', |
|
| 791 | + 'follow_location' => false, |
|
| 792 | + ); |
|
| 793 | + if (!is_null($taille_max)) { |
|
| 794 | + $options['taille_max'] = $taille_max; |
|
| 795 | + } |
|
| 796 | + // dix tentatives maximum en cas d'entetes 301... |
|
| 797 | + $res = recuperer_url($url, $options); |
|
| 798 | + |
|
| 799 | + if (!$res) { |
|
| 800 | + return false; |
|
| 801 | + } |
|
| 802 | + if ($res['status'] !== 200) { |
|
| 803 | + return false; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + return array($res['headers'], $res['page']); |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
@@ -821,41 +821,41 @@ discard block |
||
| 821 | 821 | * string contenu de la resource |
| 822 | 822 | */ |
| 823 | 823 | function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
| 824 | - $taille = 0; |
|
| 825 | - $result = ''; |
|
| 826 | - $fp = false; |
|
| 827 | - if ($fichier) { |
|
| 828 | - include_spip('inc/acces'); |
|
| 829 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 830 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 831 | - if (!$fp and file_exists($fichier)) { |
|
| 832 | - return filesize($fichier); |
|
| 833 | - } |
|
| 834 | - if (!$fp) { |
|
| 835 | - return false; |
|
| 836 | - } |
|
| 837 | - $result = 0; // on renvoie la taille du fichier |
|
| 838 | - } |
|
| 839 | - while (!feof($handle) and $taille < $taille_max) { |
|
| 840 | - $res = fread($handle, 16384); |
|
| 841 | - $taille += strlen($res); |
|
| 842 | - if ($fp) { |
|
| 843 | - fwrite($fp, $res); |
|
| 844 | - $result = $taille; |
|
| 845 | - } else { |
|
| 846 | - $result .= $res; |
|
| 847 | - } |
|
| 848 | - } |
|
| 849 | - if ($fp) { |
|
| 850 | - spip_fclose_unlock($fp); |
|
| 851 | - spip_unlink($fichier); |
|
| 852 | - @rename($tmpfile, $fichier); |
|
| 853 | - if (!file_exists($fichier)) { |
|
| 854 | - return false; |
|
| 855 | - } |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - return $result; |
|
| 824 | + $taille = 0; |
|
| 825 | + $result = ''; |
|
| 826 | + $fp = false; |
|
| 827 | + if ($fichier) { |
|
| 828 | + include_spip('inc/acces'); |
|
| 829 | + $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 830 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 831 | + if (!$fp and file_exists($fichier)) { |
|
| 832 | + return filesize($fichier); |
|
| 833 | + } |
|
| 834 | + if (!$fp) { |
|
| 835 | + return false; |
|
| 836 | + } |
|
| 837 | + $result = 0; // on renvoie la taille du fichier |
|
| 838 | + } |
|
| 839 | + while (!feof($handle) and $taille < $taille_max) { |
|
| 840 | + $res = fread($handle, 16384); |
|
| 841 | + $taille += strlen($res); |
|
| 842 | + if ($fp) { |
|
| 843 | + fwrite($fp, $res); |
|
| 844 | + $result = $taille; |
|
| 845 | + } else { |
|
| 846 | + $result .= $res; |
|
| 847 | + } |
|
| 848 | + } |
|
| 849 | + if ($fp) { |
|
| 850 | + spip_fclose_unlock($fp); |
|
| 851 | + spip_unlink($fichier); |
|
| 852 | + @rename($tmpfile, $fichier); |
|
| 853 | + if (!file_exists($fichier)) { |
|
| 854 | + return false; |
|
| 855 | + } |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + return $result; |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | /** |
@@ -877,34 +877,34 @@ discard block |
||
| 877 | 877 | * string location |
| 878 | 878 | */ |
| 879 | 879 | function recuperer_entetes_complets($handle, $if_modified_since = false) { |
| 880 | - $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => ''); |
|
| 881 | - |
|
| 882 | - $s = @trim(fgets($handle, 16384)); |
|
| 883 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 884 | - return false; |
|
| 885 | - } |
|
| 886 | - $result['status'] = intval($r[1]); |
|
| 887 | - while ($s = trim(fgets($handle, 16384))) { |
|
| 888 | - $result['headers'][] = $s . "\n"; |
|
| 889 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 890 | - list(, $d, $v) = $r; |
|
| 891 | - if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 892 | - $result['location'] = $v; |
|
| 893 | - } elseif ($d == 'Last-Modified') { |
|
| 894 | - $result['last_modified'] = strtotime($v); |
|
| 895 | - } |
|
| 896 | - } |
|
| 897 | - if ($if_modified_since |
|
| 898 | - and $result['last_modified'] |
|
| 899 | - and $if_modified_since > $result['last_modified'] |
|
| 900 | - and $result['status'] == 200 |
|
| 901 | - ) { |
|
| 902 | - $result['status'] = 304; |
|
| 903 | - } |
|
| 904 | - |
|
| 905 | - $result['headers'] = implode('', $result['headers']); |
|
| 906 | - |
|
| 907 | - return $result; |
|
| 880 | + $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => ''); |
|
| 881 | + |
|
| 882 | + $s = @trim(fgets($handle, 16384)); |
|
| 883 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 884 | + return false; |
|
| 885 | + } |
|
| 886 | + $result['status'] = intval($r[1]); |
|
| 887 | + while ($s = trim(fgets($handle, 16384))) { |
|
| 888 | + $result['headers'][] = $s . "\n"; |
|
| 889 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 890 | + list(, $d, $v) = $r; |
|
| 891 | + if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 892 | + $result['location'] = $v; |
|
| 893 | + } elseif ($d == 'Last-Modified') { |
|
| 894 | + $result['last_modified'] = strtotime($v); |
|
| 895 | + } |
|
| 896 | + } |
|
| 897 | + if ($if_modified_since |
|
| 898 | + and $result['last_modified'] |
|
| 899 | + and $if_modified_since > $result['last_modified'] |
|
| 900 | + and $result['status'] == 200 |
|
| 901 | + ) { |
|
| 902 | + $result['status'] = 304; |
|
| 903 | + } |
|
| 904 | + |
|
| 905 | + $result['headers'] = implode('', $result['headers']); |
|
| 906 | + |
|
| 907 | + return $result; |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | /** |
@@ -926,20 +926,20 @@ discard block |
||
| 926 | 926 | * - le tableau des entetes dans tous les autres cas |
| 927 | 927 | **/ |
| 928 | 928 | function recuperer_entetes($f, $date_verif = '') { |
| 929 | - //Cas ou la page distante n'a pas bouge depuis |
|
| 930 | - //la derniere visite |
|
| 931 | - $res = recuperer_entetes_complets($f, $date_verif); |
|
| 932 | - if (!$res) { |
|
| 933 | - return false; |
|
| 934 | - } |
|
| 935 | - if ($res['location']) { |
|
| 936 | - return $res['location']; |
|
| 937 | - } |
|
| 938 | - if ($res['status'] != 200) { |
|
| 939 | - return $res['status']; |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - return explode("\n", $res['headers']); |
|
| 929 | + //Cas ou la page distante n'a pas bouge depuis |
|
| 930 | + //la derniere visite |
|
| 931 | + $res = recuperer_entetes_complets($f, $date_verif); |
|
| 932 | + if (!$res) { |
|
| 933 | + return false; |
|
| 934 | + } |
|
| 935 | + if ($res['location']) { |
|
| 936 | + return $res['location']; |
|
| 937 | + } |
|
| 938 | + if ($res['status'] != 200) { |
|
| 939 | + return $res['status']; |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + return explode("\n", $res['headers']); |
|
| 943 | 943 | } |
| 944 | 944 | |
| 945 | 945 | /** |
@@ -961,22 +961,22 @@ discard block |
||
| 961 | 961 | * Nom du fichier pour copie locale |
| 962 | 962 | **/ |
| 963 | 963 | function nom_fichier_copie_locale($source, $extension) { |
| 964 | - include_spip('inc/documents'); |
|
| 964 | + include_spip('inc/documents'); |
|
| 965 | 965 | |
| 966 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 967 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 966 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 967 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 968 | 968 | |
| 969 | - // on se place tout le temps comme si on etait a la racine |
|
| 970 | - if (_DIR_RACINE) { |
|
| 971 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 972 | - } |
|
| 969 | + // on se place tout le temps comme si on etait a la racine |
|
| 970 | + if (_DIR_RACINE) { |
|
| 971 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 972 | + } |
|
| 973 | 973 | |
| 974 | - $m = md5($source); |
|
| 974 | + $m = md5($source); |
|
| 975 | 975 | |
| 976 | - return $d |
|
| 977 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 978 | - . substr($m, 0, 4) |
|
| 979 | - . ".$extension"; |
|
| 976 | + return $d |
|
| 977 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 978 | + . substr($m, 0, 4) |
|
| 979 | + . ".$extension"; |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | /** |
@@ -994,68 +994,68 @@ discard block |
||
| 994 | 994 | * Nom du fichier calculé |
| 995 | 995 | **/ |
| 996 | 996 | function fichier_copie_locale($source) { |
| 997 | - // Si c'est deja local pas de souci |
|
| 998 | - if (!tester_url_absolue($source)) { |
|
| 999 | - if (_DIR_RACINE) { |
|
| 1000 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - return $source; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 1007 | - // a deja ete copie en local avec cette extension |
|
| 1008 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 1009 | - $path_parts = pathinfo($source); |
|
| 1010 | - if (!isset($path_parts['extension'])) { |
|
| 1011 | - $path_parts['extension'] = ''; |
|
| 1012 | - } |
|
| 1013 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 1014 | - if ($ext |
|
| 1015 | - and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 1016 | - and $f = nom_fichier_copie_locale($source, $ext) |
|
| 1017 | - and file_exists(_DIR_RACINE . $f) |
|
| 1018 | - ) { |
|
| 1019 | - return $f; |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - |
|
| 1023 | - // Si c'est deja dans la table des documents, |
|
| 1024 | - // ramener le nom de sa copie potentielle |
|
| 1025 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 1026 | - |
|
| 1027 | - if ($ext) { |
|
| 1028 | - return nom_fichier_copie_locale($source, $ext); |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 1032 | - // et si il n'aurait pas deja ete rapatrie |
|
| 1033 | - |
|
| 1034 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 1035 | - |
|
| 1036 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 1037 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 1038 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 1039 | - return $f; |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - // Ping pour voir si son extension est connue et autorisee |
|
| 1044 | - // avec mise en cache du resultat du ping |
|
| 1045 | - |
|
| 1046 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 1047 | - if (!@file_exists($cache) |
|
| 1048 | - or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 1049 | - or _request('var_mode') == 'recalcul' |
|
| 1050 | - ) { |
|
| 1051 | - $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 1052 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 1053 | - } |
|
| 1054 | - $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 1055 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 1056 | - return nom_fichier_copie_locale($source, $ext); |
|
| 1057 | - } |
|
| 1058 | - spip_log("pas de copie locale pour $source"); |
|
| 997 | + // Si c'est deja local pas de souci |
|
| 998 | + if (!tester_url_absolue($source)) { |
|
| 999 | + if (_DIR_RACINE) { |
|
| 1000 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + return $source; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 1007 | + // a deja ete copie en local avec cette extension |
|
| 1008 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 1009 | + $path_parts = pathinfo($source); |
|
| 1010 | + if (!isset($path_parts['extension'])) { |
|
| 1011 | + $path_parts['extension'] = ''; |
|
| 1012 | + } |
|
| 1013 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 1014 | + if ($ext |
|
| 1015 | + and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 1016 | + and $f = nom_fichier_copie_locale($source, $ext) |
|
| 1017 | + and file_exists(_DIR_RACINE . $f) |
|
| 1018 | + ) { |
|
| 1019 | + return $f; |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + |
|
| 1023 | + // Si c'est deja dans la table des documents, |
|
| 1024 | + // ramener le nom de sa copie potentielle |
|
| 1025 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 1026 | + |
|
| 1027 | + if ($ext) { |
|
| 1028 | + return nom_fichier_copie_locale($source, $ext); |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 1032 | + // et si il n'aurait pas deja ete rapatrie |
|
| 1033 | + |
|
| 1034 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 1035 | + |
|
| 1036 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 1037 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 1038 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 1039 | + return $f; |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + // Ping pour voir si son extension est connue et autorisee |
|
| 1044 | + // avec mise en cache du resultat du ping |
|
| 1045 | + |
|
| 1046 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 1047 | + if (!@file_exists($cache) |
|
| 1048 | + or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 1049 | + or _request('var_mode') == 'recalcul' |
|
| 1050 | + ) { |
|
| 1051 | + $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 1052 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 1053 | + } |
|
| 1054 | + $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 1055 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 1056 | + return nom_fichier_copie_locale($source, $ext); |
|
| 1057 | + } |
|
| 1058 | + spip_log("pas de copie locale pour $source"); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | |
@@ -1083,141 +1083,141 @@ discard block |
||
| 1083 | 1083 | **/ |
| 1084 | 1084 | function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) { |
| 1085 | 1085 | |
| 1086 | - // pas la peine de perdre son temps |
|
| 1087 | - if (!tester_url_absolue($source)) { |
|
| 1088 | - return false; |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - # charger les alias des types mime |
|
| 1092 | - include_spip('base/typedoc'); |
|
| 1093 | - |
|
| 1094 | - $a = array(); |
|
| 1095 | - $mime_type = ''; |
|
| 1096 | - // On va directement charger le debut des images et des fichiers html, |
|
| 1097 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 1098 | - // ca echoue l'utilisateur devra les entrer... |
|
| 1099 | - if ($headers = recuperer_page($source, false, true, $max, '', '', true)) { |
|
| 1100 | - list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2); |
|
| 1101 | - |
|
| 1102 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1103 | - $mime_type = (trim($regs[1])); |
|
| 1104 | - } else { |
|
| 1105 | - $mime_type = ''; |
|
| 1106 | - } // inconnu |
|
| 1107 | - |
|
| 1108 | - // Appliquer les alias |
|
| 1109 | - while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1110 | - $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - // Si on a un mime-type insignifiant |
|
| 1114 | - // text/plain,application/octet-stream ou vide |
|
| 1115 | - // c'est peut-etre que le serveur ne sait pas |
|
| 1116 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1117 | - // ou le Content-Disposition: attachment; filename=... |
|
| 1118 | - $t = null; |
|
| 1119 | - if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) { |
|
| 1120 | - if (!$t |
|
| 1121 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1122 | - ) { |
|
| 1123 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1124 | - } |
|
| 1125 | - if (!$t |
|
| 1126 | - and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1127 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1128 | - ) { |
|
| 1129 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1130 | - } |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1134 | - if (!$t) { |
|
| 1135 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1139 | - // On essaie de nouveau avec l'extension |
|
| 1140 | - if (!$t |
|
| 1141 | - and $mime_type != 'text/plain' |
|
| 1142 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1143 | - ) { |
|
| 1144 | - # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1145 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - if ($t) { |
|
| 1149 | - spip_log("mime-type $mime_type ok, extension " . $t['extension']); |
|
| 1150 | - $a['extension'] = $t['extension']; |
|
| 1151 | - } else { |
|
| 1152 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1153 | - spip_log("mime-type $mime_type inconnu"); |
|
| 1154 | - $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1155 | - if (!$t) { |
|
| 1156 | - return false; |
|
| 1157 | - } |
|
| 1158 | - $a['extension'] = $t['extension']; |
|
| 1159 | - } |
|
| 1160 | - |
|
| 1161 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1162 | - $a['taille'] = intval($regs[1]); |
|
| 1163 | - } |
|
| 1164 | - } |
|
| 1165 | - |
|
| 1166 | - // Echec avec HEAD, on tente avec GET |
|
| 1167 | - if (!$a and !$max) { |
|
| 1168 | - spip_log("tenter GET $source"); |
|
| 1169 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - // si on a rien trouve pas la peine d'insister |
|
| 1173 | - if (!$a) { |
|
| 1174 | - return false; |
|
| 1175 | - } |
|
| 1176 | - |
|
| 1177 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1178 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1179 | - if (preg_match(',^image/(jpeg|gif|png|swf),', $mime_type)) { |
|
| 1180 | - if ($max == 0 |
|
| 1181 | - and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1182 | - and isset($GLOBALS['meta']['formats_graphiques']) |
|
| 1183 | - and (strpos($GLOBALS['meta']['formats_graphiques'], $a['extension']) !== false) |
|
| 1184 | - and $charger_si_petite_image |
|
| 1185 | - ) { |
|
| 1186 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1187 | - } else { |
|
| 1188 | - if ($a['body']) { |
|
| 1189 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']); |
|
| 1190 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 1191 | - $size_image = @getimagesize($a['fichier']); |
|
| 1192 | - $a['largeur'] = intval($size_image[0]); |
|
| 1193 | - $a['hauteur'] = intval($size_image[1]); |
|
| 1194 | - $a['type_image'] = true; |
|
| 1195 | - } |
|
| 1196 | - } |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1200 | - // ce sera mieux que 0x0 |
|
| 1201 | - if ($a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1202 | - and empty($a['largeur']) |
|
| 1203 | - ) { |
|
| 1204 | - $a['largeur'] = 425; |
|
| 1205 | - $a['hauteur'] = 350; |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - if ($mime_type == 'text/html') { |
|
| 1209 | - include_spip('inc/filtres'); |
|
| 1210 | - $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE); |
|
| 1211 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1212 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1213 | - } |
|
| 1214 | - if (!isset($a['taille']) or !$a['taille']) { |
|
| 1215 | - $a['taille'] = strlen($page); # a peu pres |
|
| 1216 | - } |
|
| 1217 | - } |
|
| 1218 | - $a['mime_type'] = $mime_type; |
|
| 1219 | - |
|
| 1220 | - return $a; |
|
| 1086 | + // pas la peine de perdre son temps |
|
| 1087 | + if (!tester_url_absolue($source)) { |
|
| 1088 | + return false; |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + # charger les alias des types mime |
|
| 1092 | + include_spip('base/typedoc'); |
|
| 1093 | + |
|
| 1094 | + $a = array(); |
|
| 1095 | + $mime_type = ''; |
|
| 1096 | + // On va directement charger le debut des images et des fichiers html, |
|
| 1097 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 1098 | + // ca echoue l'utilisateur devra les entrer... |
|
| 1099 | + if ($headers = recuperer_page($source, false, true, $max, '', '', true)) { |
|
| 1100 | + list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2); |
|
| 1101 | + |
|
| 1102 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1103 | + $mime_type = (trim($regs[1])); |
|
| 1104 | + } else { |
|
| 1105 | + $mime_type = ''; |
|
| 1106 | + } // inconnu |
|
| 1107 | + |
|
| 1108 | + // Appliquer les alias |
|
| 1109 | + while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1110 | + $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + // Si on a un mime-type insignifiant |
|
| 1114 | + // text/plain,application/octet-stream ou vide |
|
| 1115 | + // c'est peut-etre que le serveur ne sait pas |
|
| 1116 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1117 | + // ou le Content-Disposition: attachment; filename=... |
|
| 1118 | + $t = null; |
|
| 1119 | + if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) { |
|
| 1120 | + if (!$t |
|
| 1121 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1122 | + ) { |
|
| 1123 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1124 | + } |
|
| 1125 | + if (!$t |
|
| 1126 | + and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1127 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1128 | + ) { |
|
| 1129 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1130 | + } |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1134 | + if (!$t) { |
|
| 1135 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1139 | + // On essaie de nouveau avec l'extension |
|
| 1140 | + if (!$t |
|
| 1141 | + and $mime_type != 'text/plain' |
|
| 1142 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1143 | + ) { |
|
| 1144 | + # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1145 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + if ($t) { |
|
| 1149 | + spip_log("mime-type $mime_type ok, extension " . $t['extension']); |
|
| 1150 | + $a['extension'] = $t['extension']; |
|
| 1151 | + } else { |
|
| 1152 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1153 | + spip_log("mime-type $mime_type inconnu"); |
|
| 1154 | + $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1155 | + if (!$t) { |
|
| 1156 | + return false; |
|
| 1157 | + } |
|
| 1158 | + $a['extension'] = $t['extension']; |
|
| 1159 | + } |
|
| 1160 | + |
|
| 1161 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1162 | + $a['taille'] = intval($regs[1]); |
|
| 1163 | + } |
|
| 1164 | + } |
|
| 1165 | + |
|
| 1166 | + // Echec avec HEAD, on tente avec GET |
|
| 1167 | + if (!$a and !$max) { |
|
| 1168 | + spip_log("tenter GET $source"); |
|
| 1169 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + // si on a rien trouve pas la peine d'insister |
|
| 1173 | + if (!$a) { |
|
| 1174 | + return false; |
|
| 1175 | + } |
|
| 1176 | + |
|
| 1177 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1178 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1179 | + if (preg_match(',^image/(jpeg|gif|png|swf),', $mime_type)) { |
|
| 1180 | + if ($max == 0 |
|
| 1181 | + and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1182 | + and isset($GLOBALS['meta']['formats_graphiques']) |
|
| 1183 | + and (strpos($GLOBALS['meta']['formats_graphiques'], $a['extension']) !== false) |
|
| 1184 | + and $charger_si_petite_image |
|
| 1185 | + ) { |
|
| 1186 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1187 | + } else { |
|
| 1188 | + if ($a['body']) { |
|
| 1189 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']); |
|
| 1190 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 1191 | + $size_image = @getimagesize($a['fichier']); |
|
| 1192 | + $a['largeur'] = intval($size_image[0]); |
|
| 1193 | + $a['hauteur'] = intval($size_image[1]); |
|
| 1194 | + $a['type_image'] = true; |
|
| 1195 | + } |
|
| 1196 | + } |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1200 | + // ce sera mieux que 0x0 |
|
| 1201 | + if ($a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1202 | + and empty($a['largeur']) |
|
| 1203 | + ) { |
|
| 1204 | + $a['largeur'] = 425; |
|
| 1205 | + $a['hauteur'] = 350; |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + if ($mime_type == 'text/html') { |
|
| 1209 | + include_spip('inc/filtres'); |
|
| 1210 | + $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE); |
|
| 1211 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1212 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1213 | + } |
|
| 1214 | + if (!isset($a['taille']) or !$a['taille']) { |
|
| 1215 | + $a['taille'] = strlen($page); # a peu pres |
|
| 1216 | + } |
|
| 1217 | + } |
|
| 1218 | + $a['mime_type'] = $mime_type; |
|
| 1219 | + |
|
| 1220 | + return $a; |
|
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | 1223 | |
@@ -1233,45 +1233,45 @@ discard block |
||
| 1233 | 1233 | * @return string |
| 1234 | 1234 | */ |
| 1235 | 1235 | function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
| 1236 | - if (is_null($http_proxy)) { |
|
| 1237 | - $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1238 | - } |
|
| 1239 | - // rien a faire si pas de proxy :) |
|
| 1240 | - if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1241 | - return ''; |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - if (is_null($http_noproxy)) { |
|
| 1245 | - $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1246 | - } |
|
| 1247 | - // si pas d'exception, on retourne le proxy |
|
| 1248 | - if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1249 | - return $http_proxy; |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1253 | - // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1254 | - $http_noproxy = str_replace("\n", " ", $http_noproxy); |
|
| 1255 | - $http_noproxy = str_replace("\r", " ", $http_noproxy); |
|
| 1256 | - $http_noproxy = " $http_noproxy "; |
|
| 1257 | - $domain = $host; |
|
| 1258 | - // si le domaine exact www.example.org est dans les exceptions |
|
| 1259 | - if (strpos($http_noproxy, " $domain ") !== false) |
|
| 1260 | - return ''; |
|
| 1261 | - |
|
| 1262 | - while (strpos($domain, '.') !== false) { |
|
| 1263 | - $domain = explode('.', $domain); |
|
| 1264 | - array_shift($domain); |
|
| 1265 | - $domain = implode('.', $domain); |
|
| 1266 | - |
|
| 1267 | - // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1268 | - if (strpos($http_noproxy, " .$domain ") !== false) { |
|
| 1269 | - return ''; |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - // ok c'est pas une exception |
|
| 1274 | - return $http_proxy; |
|
| 1236 | + if (is_null($http_proxy)) { |
|
| 1237 | + $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1238 | + } |
|
| 1239 | + // rien a faire si pas de proxy :) |
|
| 1240 | + if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1241 | + return ''; |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + if (is_null($http_noproxy)) { |
|
| 1245 | + $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1246 | + } |
|
| 1247 | + // si pas d'exception, on retourne le proxy |
|
| 1248 | + if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1249 | + return $http_proxy; |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1253 | + // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1254 | + $http_noproxy = str_replace("\n", " ", $http_noproxy); |
|
| 1255 | + $http_noproxy = str_replace("\r", " ", $http_noproxy); |
|
| 1256 | + $http_noproxy = " $http_noproxy "; |
|
| 1257 | + $domain = $host; |
|
| 1258 | + // si le domaine exact www.example.org est dans les exceptions |
|
| 1259 | + if (strpos($http_noproxy, " $domain ") !== false) |
|
| 1260 | + return ''; |
|
| 1261 | + |
|
| 1262 | + while (strpos($domain, '.') !== false) { |
|
| 1263 | + $domain = explode('.', $domain); |
|
| 1264 | + array_shift($domain); |
|
| 1265 | + $domain = implode('.', $domain); |
|
| 1266 | + |
|
| 1267 | + // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1268 | + if (strpos($http_noproxy, " .$domain ") !== false) { |
|
| 1269 | + return ''; |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + // ok c'est pas une exception |
|
| 1274 | + return $http_proxy; |
|
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | 1277 | |
@@ -1294,58 +1294,58 @@ discard block |
||
| 1294 | 1294 | * @return array |
| 1295 | 1295 | */ |
| 1296 | 1296 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') { |
| 1297 | - $user = $via_proxy = $proxy_user = ''; |
|
| 1298 | - $fopen = false; |
|
| 1299 | - |
|
| 1300 | - $t = @parse_url($url); |
|
| 1301 | - $host = $t['host']; |
|
| 1302 | - if ($t['scheme'] == 'http') { |
|
| 1303 | - $scheme = 'http'; |
|
| 1304 | - $noproxy = ''; |
|
| 1305 | - } elseif ($t['scheme'] == 'https') { |
|
| 1306 | - $scheme = 'ssl'; |
|
| 1307 | - $noproxy = 'ssl://'; |
|
| 1308 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1309 | - $t['port'] = 443; |
|
| 1310 | - } |
|
| 1311 | - } else { |
|
| 1312 | - $scheme = $t['scheme']; |
|
| 1313 | - $noproxy = $scheme . '://'; |
|
| 1314 | - } |
|
| 1315 | - if (isset($t['user'])) { |
|
| 1316 | - $user = array($t['user'], $t['pass']); |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1320 | - $port = 80; |
|
| 1321 | - } |
|
| 1322 | - if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1323 | - $path = '/'; |
|
| 1324 | - } |
|
| 1325 | - |
|
| 1326 | - if (!empty($t['query'])) { |
|
| 1327 | - $path .= '?' . $t['query']; |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1331 | - if (!$f or !is_resource($f)) { |
|
| 1332 | - // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1333 | - // ce qui correspond a $f===110 |
|
| 1334 | - if ($f !== 110 |
|
| 1335 | - and !need_proxy($host) |
|
| 1336 | - and !_request('tester_proxy') |
|
| 1337 | - and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1338 | - ) { |
|
| 1339 | - $f = @fopen($url, 'rb'); |
|
| 1340 | - spip_log("connexion vers $url par simple fopen"); |
|
| 1341 | - $fopen = true; |
|
| 1342 | - } else { |
|
| 1343 | - // echec total |
|
| 1344 | - $f = false; |
|
| 1345 | - } |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - return array($f, $fopen); |
|
| 1297 | + $user = $via_proxy = $proxy_user = ''; |
|
| 1298 | + $fopen = false; |
|
| 1299 | + |
|
| 1300 | + $t = @parse_url($url); |
|
| 1301 | + $host = $t['host']; |
|
| 1302 | + if ($t['scheme'] == 'http') { |
|
| 1303 | + $scheme = 'http'; |
|
| 1304 | + $noproxy = ''; |
|
| 1305 | + } elseif ($t['scheme'] == 'https') { |
|
| 1306 | + $scheme = 'ssl'; |
|
| 1307 | + $noproxy = 'ssl://'; |
|
| 1308 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1309 | + $t['port'] = 443; |
|
| 1310 | + } |
|
| 1311 | + } else { |
|
| 1312 | + $scheme = $t['scheme']; |
|
| 1313 | + $noproxy = $scheme . '://'; |
|
| 1314 | + } |
|
| 1315 | + if (isset($t['user'])) { |
|
| 1316 | + $user = array($t['user'], $t['pass']); |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1320 | + $port = 80; |
|
| 1321 | + } |
|
| 1322 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1323 | + $path = '/'; |
|
| 1324 | + } |
|
| 1325 | + |
|
| 1326 | + if (!empty($t['query'])) { |
|
| 1327 | + $path .= '?' . $t['query']; |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1331 | + if (!$f or !is_resource($f)) { |
|
| 1332 | + // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1333 | + // ce qui correspond a $f===110 |
|
| 1334 | + if ($f !== 110 |
|
| 1335 | + and !need_proxy($host) |
|
| 1336 | + and !_request('tester_proxy') |
|
| 1337 | + and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1338 | + ) { |
|
| 1339 | + $f = @fopen($url, 'rb'); |
|
| 1340 | + spip_log("connexion vers $url par simple fopen"); |
|
| 1341 | + $fopen = true; |
|
| 1342 | + } else { |
|
| 1343 | + // echec total |
|
| 1344 | + $f = false; |
|
| 1345 | + } |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + return array($f, $fopen); |
|
| 1349 | 1349 | } |
| 1350 | 1350 | |
| 1351 | 1351 | /** |
@@ -1380,123 +1380,123 @@ discard block |
||
| 1380 | 1380 | * resource socket vers l'url demandee |
| 1381 | 1381 | */ |
| 1382 | 1382 | function lance_requete( |
| 1383 | - $method, |
|
| 1384 | - $scheme, |
|
| 1385 | - $user, |
|
| 1386 | - $host, |
|
| 1387 | - $path, |
|
| 1388 | - $port, |
|
| 1389 | - $noproxy, |
|
| 1390 | - $refuse_gz = false, |
|
| 1391 | - $referer = '', |
|
| 1392 | - $datas = '', |
|
| 1393 | - $vers = 'HTTP/1.0', |
|
| 1394 | - $date = '' |
|
| 1383 | + $method, |
|
| 1384 | + $scheme, |
|
| 1385 | + $user, |
|
| 1386 | + $host, |
|
| 1387 | + $path, |
|
| 1388 | + $port, |
|
| 1389 | + $noproxy, |
|
| 1390 | + $refuse_gz = false, |
|
| 1391 | + $referer = '', |
|
| 1392 | + $datas = '', |
|
| 1393 | + $vers = 'HTTP/1.0', |
|
| 1394 | + $date = '' |
|
| 1395 | 1395 | ) { |
| 1396 | 1396 | |
| 1397 | - $proxy_user = ''; |
|
| 1398 | - $http_proxy = need_proxy($host); |
|
| 1399 | - if ($user) { |
|
| 1400 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1401 | - } |
|
| 1402 | - |
|
| 1403 | - $connect = ''; |
|
| 1404 | - if ($http_proxy) { |
|
| 1405 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 1406 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1407 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1408 | - . "Host: $path_host\r\n" |
|
| 1409 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1410 | - } else { |
|
| 1411 | - $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 1412 | - . (!$user ? '' : "$user@") |
|
| 1413 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1414 | - } |
|
| 1415 | - $t2 = @parse_url($http_proxy); |
|
| 1416 | - $first_host = $t2['host']; |
|
| 1417 | - if (!($port = $t2['port'])) { |
|
| 1418 | - $port = 80; |
|
| 1419 | - } |
|
| 1420 | - if ($t2['user']) { |
|
| 1421 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1422 | - } |
|
| 1423 | - } else { |
|
| 1424 | - $first_host = $noproxy . $host; |
|
| 1425 | - } |
|
| 1426 | - |
|
| 1427 | - if ($connect) { |
|
| 1428 | - $streamContext = stream_context_create(array( |
|
| 1429 | - 'ssl' => array( |
|
| 1430 | - 'verify_peer' => false, |
|
| 1431 | - 'allow_self_signed' => true, |
|
| 1432 | - 'SNI_enabled' => true, |
|
| 1433 | - 'peer_name' => $host, |
|
| 1434 | - ) |
|
| 1435 | - )); |
|
| 1436 | - if (version_compare(phpversion(), '5.6', '<')) { |
|
| 1437 | - stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host); |
|
| 1438 | - } |
|
| 1439 | - $f = @stream_socket_client( |
|
| 1440 | - "tcp://$first_host:$port", |
|
| 1441 | - $errno, |
|
| 1442 | - $errstr, |
|
| 1443 | - _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1444 | - STREAM_CLIENT_CONNECT, |
|
| 1445 | - $streamContext |
|
| 1446 | - ); |
|
| 1447 | - spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1448 | - if (!$f) { |
|
| 1449 | - spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR); |
|
| 1450 | - return $errno; |
|
| 1451 | - } |
|
| 1452 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1453 | - |
|
| 1454 | - fputs($f, $connect); |
|
| 1455 | - fputs($f, "\r\n"); |
|
| 1456 | - $res = fread($f, 1024); |
|
| 1457 | - if (!$res |
|
| 1458 | - or !count($res = explode(' ', $res)) |
|
| 1459 | - or $res[1] !== '200' |
|
| 1460 | - ) { |
|
| 1461 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1462 | - fclose($f); |
|
| 1463 | - |
|
| 1464 | - return false; |
|
| 1465 | - } |
|
| 1466 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1467 | - stream_set_blocking($f, true); |
|
| 1468 | - // envoyer le handshake |
|
| 1469 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1470 | - spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1471 | - } else { |
|
| 1472 | - $ntry = 3; |
|
| 1473 | - do { |
|
| 1474 | - $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1475 | - } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1476 | - spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1477 | - if (!$f) { |
|
| 1478 | - spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR); |
|
| 1479 | - |
|
| 1480 | - return $errno; |
|
| 1481 | - } |
|
| 1482 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1486 | - |
|
| 1487 | - $req = "$method $path $vers\r\n" |
|
| 1488 | - . "Host: $host\r\n" |
|
| 1489 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1490 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1491 | - . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1492 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1493 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1494 | - . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1495 | - . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1397 | + $proxy_user = ''; |
|
| 1398 | + $http_proxy = need_proxy($host); |
|
| 1399 | + if ($user) { |
|
| 1400 | + $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1401 | + } |
|
| 1402 | + |
|
| 1403 | + $connect = ''; |
|
| 1404 | + if ($http_proxy) { |
|
| 1405 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 1406 | + $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1407 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1408 | + . "Host: $path_host\r\n" |
|
| 1409 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1410 | + } else { |
|
| 1411 | + $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 1412 | + . (!$user ? '' : "$user@") |
|
| 1413 | + . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1414 | + } |
|
| 1415 | + $t2 = @parse_url($http_proxy); |
|
| 1416 | + $first_host = $t2['host']; |
|
| 1417 | + if (!($port = $t2['port'])) { |
|
| 1418 | + $port = 80; |
|
| 1419 | + } |
|
| 1420 | + if ($t2['user']) { |
|
| 1421 | + $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1422 | + } |
|
| 1423 | + } else { |
|
| 1424 | + $first_host = $noproxy . $host; |
|
| 1425 | + } |
|
| 1426 | + |
|
| 1427 | + if ($connect) { |
|
| 1428 | + $streamContext = stream_context_create(array( |
|
| 1429 | + 'ssl' => array( |
|
| 1430 | + 'verify_peer' => false, |
|
| 1431 | + 'allow_self_signed' => true, |
|
| 1432 | + 'SNI_enabled' => true, |
|
| 1433 | + 'peer_name' => $host, |
|
| 1434 | + ) |
|
| 1435 | + )); |
|
| 1436 | + if (version_compare(phpversion(), '5.6', '<')) { |
|
| 1437 | + stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host); |
|
| 1438 | + } |
|
| 1439 | + $f = @stream_socket_client( |
|
| 1440 | + "tcp://$first_host:$port", |
|
| 1441 | + $errno, |
|
| 1442 | + $errstr, |
|
| 1443 | + _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1444 | + STREAM_CLIENT_CONNECT, |
|
| 1445 | + $streamContext |
|
| 1446 | + ); |
|
| 1447 | + spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1448 | + if (!$f) { |
|
| 1449 | + spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR); |
|
| 1450 | + return $errno; |
|
| 1451 | + } |
|
| 1452 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1453 | + |
|
| 1454 | + fputs($f, $connect); |
|
| 1455 | + fputs($f, "\r\n"); |
|
| 1456 | + $res = fread($f, 1024); |
|
| 1457 | + if (!$res |
|
| 1458 | + or !count($res = explode(' ', $res)) |
|
| 1459 | + or $res[1] !== '200' |
|
| 1460 | + ) { |
|
| 1461 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1462 | + fclose($f); |
|
| 1463 | + |
|
| 1464 | + return false; |
|
| 1465 | + } |
|
| 1466 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1467 | + stream_set_blocking($f, true); |
|
| 1468 | + // envoyer le handshake |
|
| 1469 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1470 | + spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1471 | + } else { |
|
| 1472 | + $ntry = 3; |
|
| 1473 | + do { |
|
| 1474 | + $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1475 | + } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1476 | + spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1477 | + if (!$f) { |
|
| 1478 | + spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR); |
|
| 1479 | + |
|
| 1480 | + return $errno; |
|
| 1481 | + } |
|
| 1482 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1486 | + |
|
| 1487 | + $req = "$method $path $vers\r\n" |
|
| 1488 | + . "Host: $host\r\n" |
|
| 1489 | + . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1490 | + . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1491 | + . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1492 | + . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1493 | + . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1494 | + . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1495 | + . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1496 | 1496 | |
| 1497 | 1497 | # spip_log("Requete\n$req"); |
| 1498 | - fputs($f, $req); |
|
| 1499 | - fputs($f, $datas ? $datas : "\r\n"); |
|
| 1498 | + fputs($f, $req); |
|
| 1499 | + fputs($f, $datas ? $datas : "\r\n"); |
|
| 1500 | 1500 | |
| 1501 | - return $f; |
|
| 1501 | + return $f; |
|
| 1502 | 1502 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | 32 | define('_INC_DISTANT_MAX_SIZE', 2097152); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | -define('_REGEXP_COPIE_LOCALE', ',' . |
|
| 38 | +define('_REGEXP_COPIE_LOCALE', ','. |
|
| 39 | 39 | preg_replace( |
| 40 | 40 | '@^https?:@', |
| 41 | 41 | 'https?:', |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | // si c'est la protection de soi-meme, retourner le path |
| 72 | 72 | if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]); |
|
| 74 | 74 | |
| 75 | 75 | return @file_exists($source) ? $source : false; |
| 76 | 76 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | return false; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 93 | + $localrac = _DIR_RACINE.$local; |
|
| 94 | 94 | $t = ($mode == 'force') ? false : @file_exists($localrac); |
| 95 | 95 | |
| 96 | 96 | // test d'existence du fichier |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '') |
| 116 | 116 | ); |
| 117 | 117 | if (!$res or (!$res['length'] and $res['status'] != 304)) { |
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], _LOG_INFO_IMPORTANTE); |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".$res['status'], _LOG_INFO_IMPORTANTE); |
|
| 119 | 119 | } |
| 120 | 120 | if (!$res['length']) { |
| 121 | 121 | // si $t c'est sans doute juste un not-modified-since |
| 122 | 122 | return $t ? $local : false; |
| 123 | 123 | } |
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK'); |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille ".$res['length'].' OK'); |
|
| 125 | 125 | |
| 126 | 126 | // pour une eventuelle indexation |
| 127 | 127 | pipeline( |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * url ou false en cas d'echec |
| 154 | 154 | */ |
| 155 | 155 | function valider_url_distante($url, $known_hosts = array()) { |
| 156 | - if (!function_exists('protocole_verifier')){ |
|
| 156 | + if (!function_exists('protocole_verifier')) { |
|
| 157 | 157 | include_spip('inc/filtres_mini'); |
| 158 | 158 | } |
| 159 | 159 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | $parsed_url = parse_url($url); |
| 165 | - if (!$parsed_url or empty($parsed_url['host']) ) { |
|
| 165 | + if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 166 | 166 | return false; |
| 167 | 167 | } |
| 168 | 168 | |
@@ -203,10 +203,10 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | if ($ip) { |
| 206 | - $parts = array_map('intval', explode( '.', $ip )); |
|
| 206 | + $parts = array_map('intval', explode('.', $ip)); |
|
| 207 | 207 | if (127 === $parts[0] or 10 === $parts[0] or 0 === $parts[0] |
| 208 | - or ( 172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1] ) |
|
| 209 | - or ( 192 === $parts[0] && 168 === $parts[1] ) |
|
| 208 | + or (172 === $parts[0] and 16 <= $parts[1] and 31 >= $parts[1]) |
|
| 209 | + or (192 === $parts[0] && 168 === $parts[1]) |
|
| 210 | 210 | ) { |
| 211 | 211 | return false; |
| 212 | 212 | } |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | $port = $parsed_url['port']; |
| 221 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 221 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 222 | 222 | return $url; |
| 223 | 223 | } |
| 224 | 224 | |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | } |
| 286 | 286 | } |
| 287 | 287 | if ($taille > 500) { |
| 288 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 288 | + $boundary = substr(md5(rand().'spip'), 0, 8); |
|
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | |
@@ -313,16 +313,16 @@ discard block |
||
| 313 | 313 | } |
| 314 | 314 | } else { |
| 315 | 315 | // fabrique une chaine HTTP simple pour un POST |
| 316 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 316 | + $entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n"; |
|
| 317 | 317 | $chaine = array(); |
| 318 | 318 | if (is_array($donnees)) { |
| 319 | 319 | foreach ($donnees as $cle => $valeur) { |
| 320 | 320 | if (is_array($valeur)) { |
| 321 | 321 | foreach ($valeur as $val2) { |
| 322 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 322 | + $chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2); |
|
| 323 | 323 | } |
| 324 | 324 | } else { |
| 325 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 325 | + $chaine[] = rawurlencode($cle).'='.rawurlencode($valeur); |
|
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | $chaine = implode('&', $chaine); |
@@ -423,9 +423,9 @@ discard block |
||
| 423 | 423 | if (!empty($options['datas'])) { |
| 424 | 424 | list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
| 425 | 425 | if (stripos($head, 'Content-Length:') === false) { |
| 426 | - $head .= 'Content-Length: ' . strlen($postdata); |
|
| 426 | + $head .= 'Content-Length: '.strlen($postdata); |
|
| 427 | 427 | } |
| 428 | - $options['datas'] = $head . "\r\n\r\n" . $postdata; |
|
| 428 | + $options['datas'] = $head."\r\n\r\n".$postdata; |
|
| 429 | 429 | if (strlen($postdata)) { |
| 430 | 430 | $options['methode'] = 'POST'; |
| 431 | 431 | } |
@@ -434,9 +434,9 @@ discard block |
||
| 434 | 434 | // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
| 435 | 435 | $url = preg_replace(',^feed://,i', 'http://', $url); |
| 436 | 436 | if (!tester_url_absolue($url)) { |
| 437 | - $url = 'http://' . $url; |
|
| 437 | + $url = 'http://'.$url; |
|
| 438 | 438 | } elseif (strncmp($url, '//', 2) == 0) { |
| 439 | - $url = 'http:' . $url; |
|
| 439 | + $url = 'http:'.$url; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | $url = url_to_ascii($url); |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | |
| 506 | 506 | return recuperer_url($url, $options); |
| 507 | 507 | } elseif ($res['status'] !== 200) { |
| 508 | - spip_log('HTTP status ' . $res['status'] . " pour $url"); |
|
| 508 | + spip_log('HTTP status '.$res['status']." pour $url"); |
|
| 509 | 509 | } |
| 510 | 510 | $result['status'] = $res['status']; |
| 511 | 511 | if (isset($res['headers'])) { |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | |
| 531 | 531 | $gz = false; |
| 532 | 532 | if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
| 533 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 533 | + $gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz'); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | // si on a pas deja recuperer le contenu par une methode detournee |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | $sig['url'] = $url; |
| 614 | 614 | |
| 615 | 615 | $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
| 616 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 616 | + $cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 617 | 617 | $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
| 618 | 618 | $cache = "$sub$cache"; |
| 619 | 619 | |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | return false; |
| 723 | 723 | } |
| 724 | 724 | if ($get_headers) { |
| 725 | - return $res['headers'] . "\n" . $res['page']; |
|
| 725 | + return $res['headers']."\n".$res['page']; |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | return $res['page']; |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | $fp = false; |
| 827 | 827 | if ($fichier) { |
| 828 | 828 | include_spip('inc/acces'); |
| 829 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 829 | + $tmpfile = "$fichier.".creer_uniqid().'.tmp'; |
|
| 830 | 830 | $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
| 831 | 831 | if (!$fp and file_exists($fichier)) { |
| 832 | 832 | return filesize($fichier); |
@@ -885,7 +885,7 @@ discard block |
||
| 885 | 885 | } |
| 886 | 886 | $result['status'] = intval($r[1]); |
| 887 | 887 | while ($s = trim(fgets($handle, 16384))) { |
| 888 | - $result['headers'][] = $s . "\n"; |
|
| 888 | + $result['headers'][] = $s."\n"; |
|
| 889 | 889 | preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
| 890 | 890 | list(, $d, $v) = $r; |
| 891 | 891 | if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
@@ -968,13 +968,13 @@ discard block |
||
| 968 | 968 | |
| 969 | 969 | // on se place tout le temps comme si on etait a la racine |
| 970 | 970 | if (_DIR_RACINE) { |
| 971 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 971 | + $d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d); |
|
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | $m = md5($source); |
| 975 | 975 | |
| 976 | 976 | return $d |
| 977 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 977 | + . substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12) |
|
| 978 | 978 | . substr($m, 0, 4) |
| 979 | 979 | . ".$extension"; |
| 980 | 980 | } |
@@ -997,7 +997,7 @@ discard block |
||
| 997 | 997 | // Si c'est deja local pas de souci |
| 998 | 998 | if (!tester_url_absolue($source)) { |
| 999 | 999 | if (_DIR_RACINE) { |
| 1000 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 1000 | + $source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source); |
|
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | 1003 | return $source; |
@@ -1014,7 +1014,7 @@ discard block |
||
| 1014 | 1014 | if ($ext |
| 1015 | 1015 | and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
| 1016 | 1016 | and $f = nom_fichier_copie_locale($source, $ext) |
| 1017 | - and file_exists(_DIR_RACINE . $f) |
|
| 1017 | + and file_exists(_DIR_RACINE.$f) |
|
| 1018 | 1018 | ) { |
| 1019 | 1019 | return $f; |
| 1020 | 1020 | } |
@@ -1022,7 +1022,7 @@ discard block |
||
| 1022 | 1022 | |
| 1023 | 1023 | // Si c'est deja dans la table des documents, |
| 1024 | 1024 | // ramener le nom de sa copie potentielle |
| 1025 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 1025 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''"); |
|
| 1026 | 1026 | |
| 1027 | 1027 | if ($ext) { |
| 1028 | 1028 | return nom_fichier_copie_locale($source, $ext); |
@@ -1033,9 +1033,9 @@ discard block |
||
| 1033 | 1033 | |
| 1034 | 1034 | $ext = $path_parts ? $path_parts['extension'] : ''; |
| 1035 | 1035 | |
| 1036 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 1036 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 1037 | 1037 | $f = nom_fichier_copie_locale($source, $ext); |
| 1038 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 1038 | + if (file_exists(_DIR_RACINE.$f)) { |
|
| 1039 | 1039 | return $f; |
| 1040 | 1040 | } |
| 1041 | 1041 | } |
@@ -1043,7 +1043,7 @@ discard block |
||
| 1043 | 1043 | // Ping pour voir si son extension est connue et autorisee |
| 1044 | 1044 | // avec mise en cache du resultat du ping |
| 1045 | 1045 | |
| 1046 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 1046 | + $cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source); |
|
| 1047 | 1047 | if (!@file_exists($cache) |
| 1048 | 1048 | or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
| 1049 | 1049 | or _request('var_mode') == 'recalcul' |
@@ -1052,7 +1052,7 @@ discard block |
||
| 1052 | 1052 | ecrire_fichier($cache, serialize($path_parts)); |
| 1053 | 1053 | } |
| 1054 | 1054 | $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
| 1055 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 1055 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 1056 | 1056 | return nom_fichier_copie_locale($source, $ext); |
| 1057 | 1057 | } |
| 1058 | 1058 | spip_log("pas de copie locale pour $source"); |
@@ -1120,19 +1120,19 @@ discard block |
||
| 1120 | 1120 | if (!$t |
| 1121 | 1121 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1122 | 1122 | ) { |
| 1123 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1123 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1124 | 1124 | } |
| 1125 | 1125 | if (!$t |
| 1126 | 1126 | and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
| 1127 | 1127 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
| 1128 | 1128 | ) { |
| 1129 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1129 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1130 | 1130 | } |
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | 1133 | // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
| 1134 | 1134 | if (!$t) { |
| 1135 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1135 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type)); |
|
| 1136 | 1136 | } |
| 1137 | 1137 | |
| 1138 | 1138 | // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
@@ -1142,11 +1142,11 @@ discard block |
||
| 1142 | 1142 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1143 | 1143 | ) { |
| 1144 | 1144 | # eviter xxx.3 => 3gp (> SPIP 3) |
| 1145 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1145 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1146 | 1146 | } |
| 1147 | 1147 | |
| 1148 | 1148 | if ($t) { |
| 1149 | - spip_log("mime-type $mime_type ok, extension " . $t['extension']); |
|
| 1149 | + spip_log("mime-type $mime_type ok, extension ".$t['extension']); |
|
| 1150 | 1150 | $a['extension'] = $t['extension']; |
| 1151 | 1151 | } else { |
| 1152 | 1152 | # par defaut on retombe sur '.bin' si c'est autorise |
@@ -1186,7 +1186,7 @@ discard block |
||
| 1186 | 1186 | $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
| 1187 | 1187 | } else { |
| 1188 | 1188 | if ($a['body']) { |
| 1189 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']); |
|
| 1189 | + $a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $a['extension']); |
|
| 1190 | 1190 | ecrire_fichier($a['fichier'], $a['body']); |
| 1191 | 1191 | $size_image = @getimagesize($a['fichier']); |
| 1192 | 1192 | $a['largeur'] = intval($size_image[0]); |
@@ -1310,7 +1310,7 @@ discard block |
||
| 1310 | 1310 | } |
| 1311 | 1311 | } else { |
| 1312 | 1312 | $scheme = $t['scheme']; |
| 1313 | - $noproxy = $scheme . '://'; |
|
| 1313 | + $noproxy = $scheme.'://'; |
|
| 1314 | 1314 | } |
| 1315 | 1315 | if (isset($t['user'])) { |
| 1316 | 1316 | $user = array($t['user'], $t['pass']); |
@@ -1324,7 +1324,7 @@ discard block |
||
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | if (!empty($t['query'])) { |
| 1327 | - $path .= '?' . $t['query']; |
|
| 1327 | + $path .= '?'.$t['query']; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
@@ -1397,20 +1397,20 @@ discard block |
||
| 1397 | 1397 | $proxy_user = ''; |
| 1398 | 1398 | $http_proxy = need_proxy($host); |
| 1399 | 1399 | if ($user) { |
| 1400 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1400 | + $user = urlencode($user[0]).':'.urlencode($user[1]); |
|
| 1401 | 1401 | } |
| 1402 | 1402 | |
| 1403 | 1403 | $connect = ''; |
| 1404 | 1404 | if ($http_proxy) { |
| 1405 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 1406 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1407 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1405 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, array('tls', 'ssl'))) { |
|
| 1406 | + $path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : ''); |
|
| 1407 | + $connect = 'CONNECT '.$path_host." $vers\r\n" |
|
| 1408 | 1408 | . "Host: $path_host\r\n" |
| 1409 | 1409 | . "Proxy-Connection: Keep-Alive\r\n"; |
| 1410 | 1410 | } else { |
| 1411 | - $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 1411 | + $path = (in_array($scheme, array('tls', 'ssl')) ? 'https://' : "$scheme://") |
|
| 1412 | 1412 | . (!$user ? '' : "$user@") |
| 1413 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1413 | + . "$host".(($port != 80) ? ":$port" : '').$path; |
|
| 1414 | 1414 | } |
| 1415 | 1415 | $t2 = @parse_url($http_proxy); |
| 1416 | 1416 | $first_host = $t2['host']; |
@@ -1418,10 +1418,10 @@ discard block |
||
| 1418 | 1418 | $port = 80; |
| 1419 | 1419 | } |
| 1420 | 1420 | if ($t2['user']) { |
| 1421 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1421 | + $proxy_user = base64_encode($t2['user'].':'.$t2['pass']); |
|
| 1422 | 1422 | } |
| 1423 | 1423 | } else { |
| 1424 | - $first_host = $noproxy . $host; |
|
| 1424 | + $first_host = $noproxy.$host; |
|
| 1425 | 1425 | } |
| 1426 | 1426 | |
| 1427 | 1427 | if ($connect) { |
@@ -1458,7 +1458,7 @@ discard block |
||
| 1458 | 1458 | or !count($res = explode(' ', $res)) |
| 1459 | 1459 | or $res[1] !== '200' |
| 1460 | 1460 | ) { |
| 1461 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1461 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE); |
|
| 1462 | 1462 | fclose($f); |
| 1463 | 1463 | |
| 1464 | 1464 | return false; |
@@ -1486,11 +1486,11 @@ discard block |
||
| 1486 | 1486 | |
| 1487 | 1487 | $req = "$method $path $vers\r\n" |
| 1488 | 1488 | . "Host: $host\r\n" |
| 1489 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1490 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1489 | + . 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n" |
|
| 1490 | + . ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n")) |
|
| 1491 | 1491 | . (!$site ? '' : "Referer: $site/$referer\r\n") |
| 1492 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1493 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1492 | + . (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n")) |
|
| 1493 | + . (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n")) |
|
| 1494 | 1494 | . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
| 1495 | 1495 | . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
| 1496 | 1496 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @uses _DIR_IMG |
| 44 | 44 | * |
| 45 | 45 | * @param string $fichier |
| 46 | - * @return bool|string |
|
| 46 | + * @return string|false |
|
| 47 | 47 | */ |
| 48 | 48 | function get_spip_doc($fichier) { |
| 49 | 49 | // fichier distant |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @param string $ext |
| 126 | 126 | * @param string $orig |
| 127 | 127 | * @param string $source |
| 128 | - * @return bool|mixed|string |
|
| 128 | + * @return string|false |
|
| 129 | 129 | */ |
| 130 | 130 | function copier_document($ext, $orig, $source) { |
| 131 | 131 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * @uses sous_repertoire() |
| 163 | 163 | * |
| 164 | 164 | * @param string $type |
| 165 | - * @return bool|string |
|
| 165 | + * @return false|string |
|
| 166 | 166 | */ |
| 167 | 167 | function determine_upload($type = '') { |
| 168 | 168 | if (!function_exists('autoriser')) { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @param bool $move |
| 203 | 203 | * - `true` : on déplace le fichier source vers le fichier de destination |
| 204 | 204 | * - `false` : valeur par défaut. On ne fait que copier le fichier source vers la destination. |
| 205 | - * @return bool|mixed|string |
|
| 205 | + * @return string|false |
|
| 206 | 206 | */ |
| 207 | 207 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 208 | 208 | // Securite |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | 32 | function set_spip_doc($fichier) { |
| 33 | - if (strpos($fichier, _DIR_IMG) === 0) { |
|
| 34 | - return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | - } else { |
|
| 36 | - return $fichier; |
|
| 37 | - } // ex: fichier distant |
|
| 33 | + if (strpos($fichier, _DIR_IMG) === 0) { |
|
| 34 | + return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | + } else { |
|
| 36 | + return $fichier; |
|
| 37 | + } // ex: fichier distant |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -46,24 +46,24 @@ discard block |
||
| 46 | 46 | * @return bool|string |
| 47 | 47 | */ |
| 48 | 48 | function get_spip_doc($fichier) { |
| 49 | - // fichier distant |
|
| 50 | - if (tester_url_absolue($fichier)) { |
|
| 51 | - return $fichier; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // gestion d'erreurs, fichier='' |
|
| 55 | - if (!strlen($fichier)) { |
|
| 56 | - return false; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $fichier = ( |
|
| 60 | - strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) != 0 |
|
| 61 | - ) |
|
| 62 | - ? _DIR_IMG . $fichier |
|
| 63 | - : $fichier; |
|
| 64 | - |
|
| 65 | - // fichier normal |
|
| 66 | - return $fichier; |
|
| 49 | + // fichier distant |
|
| 50 | + if (tester_url_absolue($fichier)) { |
|
| 51 | + return $fichier; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // gestion d'erreurs, fichier='' |
|
| 55 | + if (!strlen($fichier)) { |
|
| 56 | + return false; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $fichier = ( |
|
| 60 | + strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) != 0 |
|
| 61 | + ) |
|
| 62 | + ? _DIR_IMG . $fichier |
|
| 63 | + : $fichier; |
|
| 64 | + |
|
| 65 | + // fichier normal |
|
| 66 | + return $fichier; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -77,21 +77,21 @@ discard block |
||
| 77 | 77 | * @return string |
| 78 | 78 | */ |
| 79 | 79 | function creer_repertoire_documents($ext) { |
| 80 | - $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 80 | + $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 81 | 81 | |
| 82 | - if (!$ext or !$rep) { |
|
| 83 | - spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 84 | - exit; |
|
| 85 | - } |
|
| 82 | + if (!$ext or !$rep) { |
|
| 83 | + spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 84 | + exit; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 88 | - // par exemple acces_restreint |
|
| 89 | - if (isset($GLOBALS['meta']["creer_htaccess"]) and $GLOBALS['meta']["creer_htaccess"] == 'oui') { |
|
| 90 | - include_spip('inc/acces'); |
|
| 91 | - verifier_htaccess($rep); |
|
| 92 | - } |
|
| 87 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 88 | + // par exemple acces_restreint |
|
| 89 | + if (isset($GLOBALS['meta']["creer_htaccess"]) and $GLOBALS['meta']["creer_htaccess"] == 'oui') { |
|
| 90 | + include_spip('inc/acces'); |
|
| 91 | + verifier_htaccess($rep); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $rep; |
|
| 94 | + return $rep; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -100,21 +100,21 @@ discard block |
||
| 100 | 100 | * @param string $nom |
| 101 | 101 | */ |
| 102 | 102 | function effacer_repertoire_temporaire($nom) { |
| 103 | - if ($d = opendir($nom)) { |
|
| 104 | - while (($f = readdir($d)) !== false) { |
|
| 105 | - if (is_file("$nom/$f")) { |
|
| 106 | - spip_unlink("$nom/$f"); |
|
| 107 | - } else { |
|
| 108 | - if ($f <> '.' and $f <> '..' |
|
| 109 | - and is_dir("$nom/$f") |
|
| 110 | - ) { |
|
| 111 | - effacer_repertoire_temporaire("$nom/$f"); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - closedir($d); |
|
| 117 | - @rmdir($nom); |
|
| 103 | + if ($d = opendir($nom)) { |
|
| 104 | + while (($f = readdir($d)) !== false) { |
|
| 105 | + if (is_file("$nom/$f")) { |
|
| 106 | + spip_unlink("$nom/$f"); |
|
| 107 | + } else { |
|
| 108 | + if ($f <> '.' and $f <> '..' |
|
| 109 | + and is_dir("$nom/$f") |
|
| 110 | + ) { |
|
| 111 | + effacer_repertoire_temporaire("$nom/$f"); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + closedir($d); |
|
| 117 | + @rmdir($nom); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // |
@@ -129,28 +129,28 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | function copier_document($ext, $orig, $source) { |
| 131 | 131 | |
| 132 | - $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 133 | - $dir = creer_repertoire_documents($ext); |
|
| 134 | - $dest = preg_replace("/[^.=\w-]+/", "_", |
|
| 135 | - translitteration(preg_replace("/\.([^.]+)$/", "", |
|
| 136 | - preg_replace("/<[^>]*>/", '', basename($orig))))); |
|
| 132 | + $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 133 | + $dir = creer_repertoire_documents($ext); |
|
| 134 | + $dest = preg_replace("/[^.=\w-]+/", "_", |
|
| 135 | + translitteration(preg_replace("/\.([^.]+)$/", "", |
|
| 136 | + preg_replace("/<[^>]*>/", '', basename($orig))))); |
|
| 137 | 137 | |
| 138 | - // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 139 | - // pour les images transformees par rotation (action/documenter) |
|
| 140 | - $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 138 | + // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 139 | + // pour les images transformees par rotation (action/documenter) |
|
| 140 | + $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 141 | 141 | |
| 142 | - // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 143 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 144 | - return $source; |
|
| 145 | - } |
|
| 142 | + // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 143 | + if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 144 | + return $source; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - // sinon tourner jusqu'a trouver un numero correct |
|
| 148 | - $n = 0; |
|
| 149 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 150 | - ; |
|
| 151 | - } |
|
| 147 | + // sinon tourner jusqu'a trouver un numero correct |
|
| 148 | + $n = 0; |
|
| 149 | + while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 150 | + ; |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return deplacer_fichier_upload($source, $newFile); |
|
| 153 | + return deplacer_fichier_upload($source, $newFile); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -165,28 +165,28 @@ discard block |
||
| 165 | 165 | * @return bool|string |
| 166 | 166 | */ |
| 167 | 167 | function determine_upload($type = '') { |
| 168 | - if (!function_exists('autoriser')) { |
|
| 169 | - include_spip('inc/autoriser'); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if (!autoriser('chargerftp') |
|
| 173 | - or $type == 'logos' |
|
| 174 | - ) # on ne le permet pas pour les logos |
|
| 175 | - { |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $repertoire = _DIR_TRANSFERT; |
|
| 180 | - if (!@is_dir($repertoire)) { |
|
| 181 | - $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 182 | - $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 186 | - return $repertoire; |
|
| 187 | - } else { |
|
| 188 | - return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 189 | - } |
|
| 168 | + if (!function_exists('autoriser')) { |
|
| 169 | + include_spip('inc/autoriser'); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if (!autoriser('chargerftp') |
|
| 173 | + or $type == 'logos' |
|
| 174 | + ) # on ne le permet pas pour les logos |
|
| 175 | + { |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $repertoire = _DIR_TRANSFERT; |
|
| 180 | + if (!@is_dir($repertoire)) { |
|
| 181 | + $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 182 | + $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 186 | + return $repertoire; |
|
| 187 | + } else { |
|
| 188 | + return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 189 | + } |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -205,35 +205,35 @@ discard block |
||
| 205 | 205 | * @return bool|mixed|string |
| 206 | 206 | */ |
| 207 | 207 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 208 | - // Securite |
|
| 209 | - if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 210 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 211 | - } else { |
|
| 212 | - $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - if ($move) { |
|
| 216 | - $ok = @rename($source, $dest); |
|
| 217 | - } else { |
|
| 218 | - $ok = @copy($source, $dest); |
|
| 219 | - } |
|
| 220 | - if (!$ok) { |
|
| 221 | - $ok = @move_uploaded_file($source, $dest); |
|
| 222 | - } |
|
| 223 | - if ($ok) { |
|
| 224 | - @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 225 | - } else { |
|
| 226 | - $f = @fopen($dest, 'w'); |
|
| 227 | - if ($f) { |
|
| 228 | - fclose($f); |
|
| 229 | - } else { |
|
| 230 | - include_spip('inc/flock'); |
|
| 231 | - raler_fichier($dest); |
|
| 232 | - } |
|
| 233 | - spip_unlink($dest); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - return $ok ? $dest : false; |
|
| 208 | + // Securite |
|
| 209 | + if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 210 | + $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 211 | + } else { |
|
| 212 | + $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + if ($move) { |
|
| 216 | + $ok = @rename($source, $dest); |
|
| 217 | + } else { |
|
| 218 | + $ok = @copy($source, $dest); |
|
| 219 | + } |
|
| 220 | + if (!$ok) { |
|
| 221 | + $ok = @move_uploaded_file($source, $dest); |
|
| 222 | + } |
|
| 223 | + if ($ok) { |
|
| 224 | + @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 225 | + } else { |
|
| 226 | + $f = @fopen($dest, 'w'); |
|
| 227 | + if ($f) { |
|
| 228 | + fclose($f); |
|
| 229 | + } else { |
|
| 230 | + include_spip('inc/flock'); |
|
| 231 | + raler_fichier($dest); |
|
| 232 | + } |
|
| 233 | + spip_unlink($dest); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + return $ok ? $dest : false; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | |
@@ -257,51 +257,51 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | function check_upload_error($error, $msg = '', $return = false) { |
| 259 | 259 | |
| 260 | - if (!$error) { |
|
| 261 | - return false; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 265 | - |
|
| 266 | - switch ($error) { |
|
| 267 | - |
|
| 268 | - case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 269 | - return true; |
|
| 270 | - |
|
| 271 | - # on peut affiner les differents messages d'erreur |
|
| 272 | - case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 273 | - $msg = _T('upload_limit', |
|
| 274 | - array('max' => ini_get('upload_max_filesize'))); |
|
| 275 | - break; |
|
| 276 | - case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 277 | - $msg = _T('upload_limit', |
|
| 278 | - array('max' => ini_get('upload_max_filesize'))); |
|
| 279 | - break; |
|
| 280 | - case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 281 | - $msg = _T('upload_limit', |
|
| 282 | - array('max' => ini_get('upload_max_filesize'))); |
|
| 283 | - break; |
|
| 284 | - |
|
| 285 | - default: /* autre */ |
|
| 286 | - if (!$msg) { |
|
| 287 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 288 | - . '<br />' . propre("[->http://php.net/manual/fr/features.file-upload.errors.php]"); |
|
| 289 | - } |
|
| 290 | - break; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - spip_log("erreur upload $error"); |
|
| 294 | - if ($return) { |
|
| 295 | - return $msg; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - if (_request("iframe") == "iframe") { |
|
| 299 | - echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 300 | - exit; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - include_spip('inc/minipres'); |
|
| 304 | - echo minipres($msg, |
|
| 305 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . "</button></a></div>"); |
|
| 306 | - exit; |
|
| 260 | + if (!$error) { |
|
| 261 | + return false; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 265 | + |
|
| 266 | + switch ($error) { |
|
| 267 | + |
|
| 268 | + case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 269 | + return true; |
|
| 270 | + |
|
| 271 | + # on peut affiner les differents messages d'erreur |
|
| 272 | + case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 273 | + $msg = _T('upload_limit', |
|
| 274 | + array('max' => ini_get('upload_max_filesize'))); |
|
| 275 | + break; |
|
| 276 | + case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 277 | + $msg = _T('upload_limit', |
|
| 278 | + array('max' => ini_get('upload_max_filesize'))); |
|
| 279 | + break; |
|
| 280 | + case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 281 | + $msg = _T('upload_limit', |
|
| 282 | + array('max' => ini_get('upload_max_filesize'))); |
|
| 283 | + break; |
|
| 284 | + |
|
| 285 | + default: /* autre */ |
|
| 286 | + if (!$msg) { |
|
| 287 | + $msg = _T('pass_erreur') . ' ' . $error |
|
| 288 | + . '<br />' . propre("[->http://php.net/manual/fr/features.file-upload.errors.php]"); |
|
| 289 | + } |
|
| 290 | + break; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + spip_log("erreur upload $error"); |
|
| 294 | + if ($return) { |
|
| 295 | + return $msg; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + if (_request("iframe") == "iframe") { |
|
| 299 | + echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 300 | + exit; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + include_spip('inc/minipres'); |
|
| 304 | + echo minipres($msg, |
|
| 305 | + "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . "</button></a></div>"); |
|
| 306 | + exit; |
|
| 307 | 307 | } |
@@ -171,10 +171,12 @@ |
||
| 171 | 171 | |
| 172 | 172 | if (!autoriser('chargerftp') |
| 173 | 173 | or $type == 'logos' |
| 174 | - ) # on ne le permet pas pour les logos |
|
| 174 | + ) { |
|
| 175 | + # on ne le permet pas pour les logos |
|
| 175 | 176 | { |
| 176 | 177 | return false; |
| 177 | 178 | } |
| 179 | + } |
|
| 178 | 180 | |
| 179 | 181 | $repertoire = _DIR_TRANSFERT; |
| 180 | 182 | if (!@is_dir($repertoire)) { |
@@ -140,13 +140,13 @@ discard block |
||
| 140 | 140 | $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
| 141 | 141 | |
| 142 | 142 | // Si le document "source" est deja au bon endroit, ne rien faire |
| 143 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 143 | + if ($source == ($dir.$dest.'.'.$ext)) { |
|
| 144 | 144 | return $source; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // sinon tourner jusqu'a trouver un numero correct |
| 148 | 148 | $n = 0; |
| 149 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 149 | + while (@file_exists($newFile = $dir.$dest.($n++ ? ('-'.$n) : '').'.'.$ext)) { |
|
| 150 | 150 | ; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 208 | 208 | // Securite |
| 209 | 209 | if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
| 210 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 210 | + $dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 211 | 211 | } else { |
| 212 | 212 | $dest = preg_replace(',\.\.+,', '.', $dest); |
| 213 | 213 | } |
@@ -284,8 +284,8 @@ discard block |
||
| 284 | 284 | |
| 285 | 285 | default: /* autre */ |
| 286 | 286 | if (!$msg) { |
| 287 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 288 | - . '<br />' . propre("[->http://php.net/manual/fr/features.file-upload.errors.php]"); |
|
| 287 | + $msg = _T('pass_erreur').' '.$error |
|
| 288 | + . '<br />'.propre("[->http://php.net/manual/fr/features.file-upload.errors.php]"); |
|
| 289 | 289 | } |
| 290 | 290 | break; |
| 291 | 291 | } |
@@ -302,6 +302,6 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | include_spip('inc/minipres'); |
| 304 | 304 | echo minipres($msg, |
| 305 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . "</button></a></div>"); |
|
| 305 | + "<div style='text-align: ".$GLOBALS['spip_lang_right']."'><a href='".rawurldecode($GLOBALS['redirect'])."'><button type='button'>"._T('ecrire:bouton_suivant')."</button></a></div>"); |
|
| 306 | 306 | exit; |
| 307 | 307 | } |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * utile pour les textes > 32ko |
| 315 | 315 | * |
| 316 | 316 | * @param string $texte |
| 317 | - * @return array |
|
| 317 | + * @return string[] |
|
| 318 | 318 | */ |
| 319 | 319 | function coupe_trop_long($texte) { |
| 320 | 320 | $aider = charger_fonction('aider', 'inc'); |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | * |
| 348 | 348 | * @param string $texte |
| 349 | 349 | * @param string $att_text |
| 350 | - * @return array |
|
| 350 | + * @return string[] |
|
| 351 | 351 | */ |
| 352 | 352 | function editer_texte_recolle($texte, $att_text) { |
| 353 | 353 | if ((strlen($texte) < 29 * 1024) |
@@ -373,8 +373,8 @@ discard block |
||
| 373 | 373 | /** |
| 374 | 374 | * auto-renseigner le titre si il n'existe pas |
| 375 | 375 | * |
| 376 | - * @param $champ_titre |
|
| 377 | - * @param $champs_contenu |
|
| 376 | + * @param string $champ_titre |
|
| 377 | + * @param string[] $champs_contenu |
|
| 378 | 378 | * @param int $longueur |
| 379 | 379 | */ |
| 380 | 380 | function titre_automatique($champ_titre, $champs_contenu, $longueur = null) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('base/abstract_sql'); |
| 23 | 23 | |
@@ -59,56 +59,56 @@ discard block |
||
| 59 | 59 | * Retour des traitements. |
| 60 | 60 | **/ |
| 61 | 61 | function formulaires_editer_objet_traiter( |
| 62 | - $type, |
|
| 63 | - $id = 'new', |
|
| 64 | - $id_parent = 0, |
|
| 65 | - $lier_trad = 0, |
|
| 66 | - $retour = '', |
|
| 67 | - $config_fonc = 'articles_edit_config', |
|
| 68 | - $row = array(), |
|
| 69 | - $hidden = '' |
|
| 62 | + $type, |
|
| 63 | + $id = 'new', |
|
| 64 | + $id_parent = 0, |
|
| 65 | + $lier_trad = 0, |
|
| 66 | + $retour = '', |
|
| 67 | + $config_fonc = 'articles_edit_config', |
|
| 68 | + $row = array(), |
|
| 69 | + $hidden = '' |
|
| 70 | 70 | ) { |
| 71 | 71 | |
| 72 | - $res = array(); |
|
| 73 | - // eviter la redirection forcee par l'action... |
|
| 74 | - set_request('redirect'); |
|
| 75 | - if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 76 | - list($id, $err) = $action_editer($id); |
|
| 77 | - } else { |
|
| 78 | - $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 79 | - list($id, $err) = $action_editer($id, $type); |
|
| 80 | - } |
|
| 81 | - $id_table_objet = id_table_objet($type); |
|
| 82 | - $res[$id_table_objet] = $id; |
|
| 83 | - if ($err or !$id) { |
|
| 84 | - $res['message_erreur'] = ($err ? $err : _T('erreur')); |
|
| 85 | - } else { |
|
| 86 | - // Un lien de trad a prendre en compte |
|
| 87 | - if ($lier_trad) { |
|
| 88 | - // referencer la traduction |
|
| 89 | - $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 90 | - $referencer_traduction($type, $id, $lier_trad); |
|
| 91 | - // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 92 | - $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 93 | - $err = $completer_traduction($type, $id, $lier_trad); |
|
| 94 | - if ($err) { |
|
| 95 | - $res['message_erreur'] = $err; |
|
| 96 | - return $res; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 101 | - if ($retour) { |
|
| 102 | - if (strncmp($retour, 'javascript:', 11) == 0) { |
|
| 103 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 104 | - $res['editable'] = true; |
|
| 105 | - } else { |
|
| 106 | - $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $res; |
|
| 72 | + $res = array(); |
|
| 73 | + // eviter la redirection forcee par l'action... |
|
| 74 | + set_request('redirect'); |
|
| 75 | + if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 76 | + list($id, $err) = $action_editer($id); |
|
| 77 | + } else { |
|
| 78 | + $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 79 | + list($id, $err) = $action_editer($id, $type); |
|
| 80 | + } |
|
| 81 | + $id_table_objet = id_table_objet($type); |
|
| 82 | + $res[$id_table_objet] = $id; |
|
| 83 | + if ($err or !$id) { |
|
| 84 | + $res['message_erreur'] = ($err ? $err : _T('erreur')); |
|
| 85 | + } else { |
|
| 86 | + // Un lien de trad a prendre en compte |
|
| 87 | + if ($lier_trad) { |
|
| 88 | + // referencer la traduction |
|
| 89 | + $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 90 | + $referencer_traduction($type, $id, $lier_trad); |
|
| 91 | + // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 92 | + $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 93 | + $err = $completer_traduction($type, $id, $lier_trad); |
|
| 94 | + if ($err) { |
|
| 95 | + $res['message_erreur'] = $err; |
|
| 96 | + return $res; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 101 | + if ($retour) { |
|
| 102 | + if (strncmp($retour, 'javascript:', 11) == 0) { |
|
| 103 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 104 | + $res['editable'] = true; |
|
| 105 | + } else { |
|
| 106 | + $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $res; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -132,29 +132,29 @@ discard block |
||
| 132 | 132 | * Tableau des erreurs |
| 133 | 133 | **/ |
| 134 | 134 | function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = array()) { |
| 135 | - $erreurs = array(); |
|
| 136 | - if (intval($id)) { |
|
| 137 | - $conflits = controler_contenu($type, $id); |
|
| 138 | - if ($conflits and count($conflits)) { |
|
| 139 | - foreach ($conflits as $champ => $conflit) { |
|
| 140 | - if (!isset($erreurs[$champ])) { |
|
| 141 | - $erreurs[$champ] = ''; |
|
| 142 | - } |
|
| 143 | - $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . $conflit['base'] . '</textarea>'; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - foreach ($oblis as $obli) { |
|
| 148 | - $value = _request($obli); |
|
| 149 | - if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) { |
|
| 150 | - if (!isset($erreurs[$obli])) { |
|
| 151 | - $erreurs[$obli] = ''; |
|
| 152 | - } |
|
| 153 | - $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - return $erreurs; |
|
| 135 | + $erreurs = array(); |
|
| 136 | + if (intval($id)) { |
|
| 137 | + $conflits = controler_contenu($type, $id); |
|
| 138 | + if ($conflits and count($conflits)) { |
|
| 139 | + foreach ($conflits as $champ => $conflit) { |
|
| 140 | + if (!isset($erreurs[$champ])) { |
|
| 141 | + $erreurs[$champ] = ''; |
|
| 142 | + } |
|
| 143 | + $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . $conflit['base'] . '</textarea>'; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + foreach ($oblis as $obli) { |
|
| 148 | + $value = _request($obli); |
|
| 149 | + if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) { |
|
| 150 | + if (!isset($erreurs[$obli])) { |
|
| 151 | + $erreurs[$obli] = ''; |
|
| 152 | + } |
|
| 153 | + $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + return $erreurs; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -198,115 +198,115 @@ discard block |
||
| 198 | 198 | * Environnement du formulaire. |
| 199 | 199 | **/ |
| 200 | 200 | function formulaires_editer_objet_charger( |
| 201 | - $type, |
|
| 202 | - $id = 'new', |
|
| 203 | - $id_parent = 0, |
|
| 204 | - $lier_trad = 0, |
|
| 205 | - $retour = '', |
|
| 206 | - $config_fonc = 'articles_edit_config', |
|
| 207 | - $row = array(), |
|
| 208 | - $hidden = '' |
|
| 201 | + $type, |
|
| 202 | + $id = 'new', |
|
| 203 | + $id_parent = 0, |
|
| 204 | + $lier_trad = 0, |
|
| 205 | + $retour = '', |
|
| 206 | + $config_fonc = 'articles_edit_config', |
|
| 207 | + $row = array(), |
|
| 208 | + $hidden = '' |
|
| 209 | 209 | ) { |
| 210 | - $table_objet = table_objet($type); |
|
| 211 | - $table_objet_sql = table_objet_sql($type); |
|
| 212 | - $id_table_objet = id_table_objet($type); |
|
| 213 | - $new = !is_numeric($id); |
|
| 214 | - // Appel direct dans un squelette |
|
| 215 | - if (!$row) { |
|
| 216 | - if (!$new or $lier_trad) { |
|
| 217 | - if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 218 | - $row = $select($id, $id_parent, $lier_trad); |
|
| 219 | - } else { |
|
| 220 | - $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id)); |
|
| 221 | - } |
|
| 222 | - if (!$new) { |
|
| 223 | - $md5 = controles_md5($row); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - if (!$row) { |
|
| 227 | - $row = array(); |
|
| 228 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 229 | - if ($desc = $trouver_table($table_objet)) { |
|
| 230 | - foreach ($desc['field'] as $k => $v) { |
|
| 231 | - $row[$k] = ''; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 238 | - // (et donc: pas de lien de traduction) |
|
| 239 | - $id = ($new or $lier_trad) |
|
| 240 | - ? 'oui' |
|
| 241 | - : $row[$id_table_objet]; |
|
| 242 | - $row[$id_table_objet] = $id; |
|
| 243 | - |
|
| 244 | - $contexte = $row; |
|
| 245 | - if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) { |
|
| 246 | - if (!isset($contexte['id_parent'])) { |
|
| 247 | - unset($contexte['id_rubrique']); |
|
| 248 | - } |
|
| 249 | - $contexte['id_parent'] = $id_parent; |
|
| 250 | - } elseif (!isset($contexte['id_parent'])) { |
|
| 251 | - // id_rubrique dans id_parent si possible |
|
| 252 | - if (isset($contexte['id_rubrique'])) { |
|
| 253 | - $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 254 | - unset($contexte['id_rubrique']); |
|
| 255 | - } else { |
|
| 256 | - $contexte['id_parent'] = ''; |
|
| 257 | - } |
|
| 258 | - if (!$contexte['id_parent'] |
|
| 259 | - and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true) |
|
| 260 | - ) { |
|
| 261 | - $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - $config = array(); |
|
| 266 | - if ($config_fonc) { |
|
| 267 | - $contexte['config'] = $config = $config_fonc($contexte); |
|
| 268 | - } |
|
| 269 | - $config = $config + array( |
|
| 270 | - 'lignes' => 0, |
|
| 271 | - 'langue' => '', |
|
| 272 | - ); |
|
| 273 | - |
|
| 274 | - $att_text = " class='textarea' " |
|
| 275 | - . " rows='" |
|
| 276 | - . ($config['lignes'] + 15) |
|
| 277 | - . "' cols='40'"; |
|
| 278 | - if (isset($contexte['texte'])) { |
|
| 279 | - list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // on veut conserver la langue de l'interface ; |
|
| 283 | - // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 284 | - // voudrait l'exploiter |
|
| 285 | - if (isset($contexte['lang'])) { |
|
| 286 | - $contexte['langue'] = $contexte['lang']; |
|
| 287 | - unset($contexte['lang']); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 291 | - (!$lier_trad ? '' : |
|
| 292 | - ("\n<input type='hidden' name='lier_trad' value='" . |
|
| 293 | - $lier_trad . |
|
| 294 | - "' />" . |
|
| 295 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 296 | - $config['langue'] . |
|
| 297 | - "' />")) |
|
| 298 | - . $hidden |
|
| 299 | - . (isset($md5) ? $md5 : ''); |
|
| 300 | - |
|
| 301 | - // preciser que le formulaire doit passer dans un pipeline |
|
| 302 | - $contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id)); |
|
| 303 | - |
|
| 304 | - // preciser que le formulaire doit etre securise auteur/action |
|
| 305 | - // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 306 | - // on le garde pour compat |
|
| 307 | - $contexte['_action'] = array("editer_$type", $id); |
|
| 308 | - |
|
| 309 | - return $contexte; |
|
| 210 | + $table_objet = table_objet($type); |
|
| 211 | + $table_objet_sql = table_objet_sql($type); |
|
| 212 | + $id_table_objet = id_table_objet($type); |
|
| 213 | + $new = !is_numeric($id); |
|
| 214 | + // Appel direct dans un squelette |
|
| 215 | + if (!$row) { |
|
| 216 | + if (!$new or $lier_trad) { |
|
| 217 | + if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 218 | + $row = $select($id, $id_parent, $lier_trad); |
|
| 219 | + } else { |
|
| 220 | + $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id)); |
|
| 221 | + } |
|
| 222 | + if (!$new) { |
|
| 223 | + $md5 = controles_md5($row); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + if (!$row) { |
|
| 227 | + $row = array(); |
|
| 228 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 229 | + if ($desc = $trouver_table($table_objet)) { |
|
| 230 | + foreach ($desc['field'] as $k => $v) { |
|
| 231 | + $row[$k] = ''; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 238 | + // (et donc: pas de lien de traduction) |
|
| 239 | + $id = ($new or $lier_trad) |
|
| 240 | + ? 'oui' |
|
| 241 | + : $row[$id_table_objet]; |
|
| 242 | + $row[$id_table_objet] = $id; |
|
| 243 | + |
|
| 244 | + $contexte = $row; |
|
| 245 | + if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) { |
|
| 246 | + if (!isset($contexte['id_parent'])) { |
|
| 247 | + unset($contexte['id_rubrique']); |
|
| 248 | + } |
|
| 249 | + $contexte['id_parent'] = $id_parent; |
|
| 250 | + } elseif (!isset($contexte['id_parent'])) { |
|
| 251 | + // id_rubrique dans id_parent si possible |
|
| 252 | + if (isset($contexte['id_rubrique'])) { |
|
| 253 | + $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 254 | + unset($contexte['id_rubrique']); |
|
| 255 | + } else { |
|
| 256 | + $contexte['id_parent'] = ''; |
|
| 257 | + } |
|
| 258 | + if (!$contexte['id_parent'] |
|
| 259 | + and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true) |
|
| 260 | + ) { |
|
| 261 | + $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + $config = array(); |
|
| 266 | + if ($config_fonc) { |
|
| 267 | + $contexte['config'] = $config = $config_fonc($contexte); |
|
| 268 | + } |
|
| 269 | + $config = $config + array( |
|
| 270 | + 'lignes' => 0, |
|
| 271 | + 'langue' => '', |
|
| 272 | + ); |
|
| 273 | + |
|
| 274 | + $att_text = " class='textarea' " |
|
| 275 | + . " rows='" |
|
| 276 | + . ($config['lignes'] + 15) |
|
| 277 | + . "' cols='40'"; |
|
| 278 | + if (isset($contexte['texte'])) { |
|
| 279 | + list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // on veut conserver la langue de l'interface ; |
|
| 283 | + // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 284 | + // voudrait l'exploiter |
|
| 285 | + if (isset($contexte['lang'])) { |
|
| 286 | + $contexte['langue'] = $contexte['lang']; |
|
| 287 | + unset($contexte['lang']); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 291 | + (!$lier_trad ? '' : |
|
| 292 | + ("\n<input type='hidden' name='lier_trad' value='" . |
|
| 293 | + $lier_trad . |
|
| 294 | + "' />" . |
|
| 295 | + "\n<input type='hidden' name='changer_lang' value='" . |
|
| 296 | + $config['langue'] . |
|
| 297 | + "' />")) |
|
| 298 | + . $hidden |
|
| 299 | + . (isset($md5) ? $md5 : ''); |
|
| 300 | + |
|
| 301 | + // preciser que le formulaire doit passer dans un pipeline |
|
| 302 | + $contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id)); |
|
| 303 | + |
|
| 304 | + // preciser que le formulaire doit etre securise auteur/action |
|
| 305 | + // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 306 | + // on le garde pour compat |
|
| 307 | + $contexte['_action'] = array("editer_$type", $id); |
|
| 308 | + |
|
| 309 | + return $contexte; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -317,29 +317,29 @@ discard block |
||
| 317 | 317 | * @return array |
| 318 | 318 | */ |
| 319 | 319 | function coupe_trop_long($texte) { |
| 320 | - $aider = charger_fonction('aider', 'inc'); |
|
| 321 | - if (strlen($texte) > 28 * 1024) { |
|
| 322 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 323 | - $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 324 | - if ($pos > 0 and $pos < 32 * 1024) { |
|
| 325 | - $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 326 | - $suite = substr($texte, $pos + 2); |
|
| 327 | - } else { |
|
| 328 | - $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 329 | - if (!($pos > 0 and $pos < 32 * 1024)) { |
|
| 330 | - $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 331 | - $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 332 | - } else { |
|
| 333 | - $decalage = 1; |
|
| 334 | - } |
|
| 335 | - $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 336 | - $suite = substr($texte, $pos + $decalage); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - return (array($debut, $suite)); |
|
| 340 | - } else { |
|
| 341 | - return (array($texte, '')); |
|
| 342 | - } |
|
| 320 | + $aider = charger_fonction('aider', 'inc'); |
|
| 321 | + if (strlen($texte) > 28 * 1024) { |
|
| 322 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 323 | + $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 324 | + if ($pos > 0 and $pos < 32 * 1024) { |
|
| 325 | + $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 326 | + $suite = substr($texte, $pos + 2); |
|
| 327 | + } else { |
|
| 328 | + $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 329 | + if (!($pos > 0 and $pos < 32 * 1024)) { |
|
| 330 | + $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 331 | + $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 332 | + } else { |
|
| 333 | + $decalage = 1; |
|
| 334 | + } |
|
| 335 | + $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 336 | + $suite = substr($texte, $pos + $decalage); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + return (array($debut, $suite)); |
|
| 340 | + } else { |
|
| 341 | + return (array($texte, '')); |
|
| 342 | + } |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | /** |
@@ -350,24 +350,24 @@ discard block |
||
| 350 | 350 | * @return array |
| 351 | 351 | */ |
| 352 | 352 | function editer_texte_recolle($texte, $att_text) { |
| 353 | - if ((strlen($texte) < 29 * 1024) |
|
| 354 | - or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE')) |
|
| 355 | - ) { |
|
| 356 | - return array($texte, ''); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - include_spip('inc/barre'); |
|
| 360 | - $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n"; |
|
| 361 | - $nombre = 0; |
|
| 362 | - |
|
| 363 | - while (strlen($texte) > 29 * 1024) { |
|
| 364 | - $nombre++; |
|
| 365 | - list($texte1, $texte) = coupe_trop_long($texte); |
|
| 366 | - $textes_supplement .= '<br />' . |
|
| 367 | - "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n"; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - return array($texte, $textes_supplement); |
|
| 353 | + if ((strlen($texte) < 29 * 1024) |
|
| 354 | + or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE')) |
|
| 355 | + ) { |
|
| 356 | + return array($texte, ''); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + include_spip('inc/barre'); |
|
| 360 | + $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n"; |
|
| 361 | + $nombre = 0; |
|
| 362 | + |
|
| 363 | + while (strlen($texte) > 29 * 1024) { |
|
| 364 | + $nombre++; |
|
| 365 | + list($texte1, $texte) = coupe_trop_long($texte); |
|
| 366 | + $textes_supplement .= '<br />' . |
|
| 367 | + "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n"; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + return array($texte, $textes_supplement); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | /** |
@@ -378,17 +378,17 @@ discard block |
||
| 378 | 378 | * @param int $longueur |
| 379 | 379 | */ |
| 380 | 380 | function titre_automatique($champ_titre, $champs_contenu, $longueur = null) { |
| 381 | - if (!_request($champ_titre)) { |
|
| 382 | - $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 383 | - if (!is_null($longueur)) { |
|
| 384 | - $t = $titrer_contenu($champs_contenu, null, $longueur); |
|
| 385 | - } else { |
|
| 386 | - $t = $titrer_contenu($champs_contenu); |
|
| 387 | - } |
|
| 388 | - if ($t) { |
|
| 389 | - set_request($champ_titre, $t); |
|
| 390 | - } |
|
| 391 | - } |
|
| 381 | + if (!_request($champ_titre)) { |
|
| 382 | + $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 383 | + if (!is_null($longueur)) { |
|
| 384 | + $t = $titrer_contenu($champs_contenu, null, $longueur); |
|
| 385 | + } else { |
|
| 386 | + $t = $titrer_contenu($champs_contenu); |
|
| 387 | + } |
|
| 388 | + if ($t) { |
|
| 389 | + set_request($champ_titre, $t); |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -408,20 +408,20 @@ discard block |
||
| 408 | 408 | * @return string |
| 409 | 409 | */ |
| 410 | 410 | function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) { |
| 411 | - // trouver un champ texte non vide |
|
| 412 | - $t = ''; |
|
| 413 | - foreach ($champs_contenu as $champ) { |
|
| 414 | - if ($t = _request($champ, $c)) { |
|
| 415 | - break; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - if ($t) { |
|
| 420 | - include_spip('inc/texte_mini'); |
|
| 421 | - $t = couper($t, $longueur, '...'); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - return $t; |
|
| 411 | + // trouver un champ texte non vide |
|
| 412 | + $t = ''; |
|
| 413 | + foreach ($champs_contenu as $champ) { |
|
| 414 | + if ($t = _request($champ, $c)) { |
|
| 415 | + break; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + if ($t) { |
|
| 420 | + include_spip('inc/texte_mini'); |
|
| 421 | + $t = couper($t, $longueur, '...'); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + return $t; |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
@@ -444,30 +444,30 @@ discard block |
||
| 444 | 444 | * - array sinon couples ('$prefixe$colonne => md5) |
| 445 | 445 | **/ |
| 446 | 446 | function controles_md5($data, $prefixe = 'ctr_', $format = 'html') { |
| 447 | - if (!is_array($data)) { |
|
| 448 | - return false; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - $ctr = array(); |
|
| 452 | - foreach ($data as $key => $val) { |
|
| 453 | - $m = md5($val); |
|
| 454 | - $k = $prefixe . $key; |
|
| 455 | - |
|
| 456 | - switch ($format) { |
|
| 457 | - case 'html': |
|
| 458 | - $ctr[$k] = "<input type='hidden' value='$m' name='$k' />"; |
|
| 459 | - break; |
|
| 460 | - default: |
|
| 461 | - $ctr[$k] = $m; |
|
| 462 | - break; |
|
| 463 | - } |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - if ($format == 'html') { |
|
| 467 | - return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n"; |
|
| 468 | - } else { |
|
| 469 | - return $ctr; |
|
| 470 | - } |
|
| 447 | + if (!is_array($data)) { |
|
| 448 | + return false; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + $ctr = array(); |
|
| 452 | + foreach ($data as $key => $val) { |
|
| 453 | + $m = md5($val); |
|
| 454 | + $k = $prefixe . $key; |
|
| 455 | + |
|
| 456 | + switch ($format) { |
|
| 457 | + case 'html': |
|
| 458 | + $ctr[$k] = "<input type='hidden' value='$m' name='$k' />"; |
|
| 459 | + break; |
|
| 460 | + default: |
|
| 461 | + $ctr[$k] = $m; |
|
| 462 | + break; |
|
| 463 | + } |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + if ($format == 'html') { |
|
| 467 | + return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n"; |
|
| 468 | + } else { |
|
| 469 | + return $ctr; |
|
| 470 | + } |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | /** |
@@ -506,79 +506,79 @@ discard block |
||
| 506 | 506 | * - post : le contenu posté |
| 507 | 507 | **/ |
| 508 | 508 | function controler_contenu($type, $id, $options = array(), $c = false, $serveur = '') { |
| 509 | - include_spip('inc/filtres'); |
|
| 510 | - |
|
| 511 | - $table_objet = table_objet($type); |
|
| 512 | - $spip_table_objet = table_objet_sql($type); |
|
| 513 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 514 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 515 | - |
|
| 516 | - // Appels incomplets (sans $c) |
|
| 517 | - if (!is_array($c)) { |
|
| 518 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 519 | - if (_request($champ)) { |
|
| 520 | - $c[$champ] = _request($champ); |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 526 | - // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 527 | - // il faut passer par instituer_XX() |
|
| 528 | - // TODO: faut-il passer ces variables interdites |
|
| 529 | - // dans un fichier de description separe ? |
|
| 530 | - unset($c['statut']); |
|
| 531 | - unset($c['id_parent']); |
|
| 532 | - unset($c['id_rubrique']); |
|
| 533 | - unset($c['id_secteur']); |
|
| 534 | - |
|
| 535 | - // Gerer les champs non vides |
|
| 536 | - if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 537 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 538 | - if ($c[$champ] === '') { |
|
| 539 | - $c[$champ] = $sinon; |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // N'accepter que les champs qui existent |
|
| 545 | - // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 546 | - $champs = array(); |
|
| 547 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 548 | - if (isset($c[$champ])) { |
|
| 549 | - $champs[$champ] = $c[$champ]; |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - // Nettoyer les valeurs |
|
| 554 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 555 | - |
|
| 556 | - // Envoyer aux plugins |
|
| 557 | - $champs = pipeline( |
|
| 558 | - 'pre_edition', |
|
| 559 | - array( |
|
| 560 | - 'args' => array( |
|
| 561 | - 'table' => $spip_table_objet, // compatibilite |
|
| 562 | - 'table_objet' => $table_objet, |
|
| 563 | - 'spip_table_objet' => $spip_table_objet, |
|
| 564 | - 'type' => $type, |
|
| 565 | - 'id_objet' => $id, |
|
| 566 | - 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ? |
|
| 567 | - 'action' => 'controler', |
|
| 568 | - 'serveur' => $serveur, |
|
| 569 | - ), |
|
| 570 | - 'data' => $champs |
|
| 571 | - ) |
|
| 572 | - ); |
|
| 573 | - |
|
| 574 | - if (!$champs) { |
|
| 575 | - return false; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 579 | - $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_'); |
|
| 580 | - |
|
| 581 | - return $conflits; |
|
| 509 | + include_spip('inc/filtres'); |
|
| 510 | + |
|
| 511 | + $table_objet = table_objet($type); |
|
| 512 | + $spip_table_objet = table_objet_sql($type); |
|
| 513 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 514 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 515 | + |
|
| 516 | + // Appels incomplets (sans $c) |
|
| 517 | + if (!is_array($c)) { |
|
| 518 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 519 | + if (_request($champ)) { |
|
| 520 | + $c[$champ] = _request($champ); |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 526 | + // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 527 | + // il faut passer par instituer_XX() |
|
| 528 | + // TODO: faut-il passer ces variables interdites |
|
| 529 | + // dans un fichier de description separe ? |
|
| 530 | + unset($c['statut']); |
|
| 531 | + unset($c['id_parent']); |
|
| 532 | + unset($c['id_rubrique']); |
|
| 533 | + unset($c['id_secteur']); |
|
| 534 | + |
|
| 535 | + // Gerer les champs non vides |
|
| 536 | + if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 537 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 538 | + if ($c[$champ] === '') { |
|
| 539 | + $c[$champ] = $sinon; |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // N'accepter que les champs qui existent |
|
| 545 | + // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 546 | + $champs = array(); |
|
| 547 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 548 | + if (isset($c[$champ])) { |
|
| 549 | + $champs[$champ] = $c[$champ]; |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + // Nettoyer les valeurs |
|
| 554 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 555 | + |
|
| 556 | + // Envoyer aux plugins |
|
| 557 | + $champs = pipeline( |
|
| 558 | + 'pre_edition', |
|
| 559 | + array( |
|
| 560 | + 'args' => array( |
|
| 561 | + 'table' => $spip_table_objet, // compatibilite |
|
| 562 | + 'table_objet' => $table_objet, |
|
| 563 | + 'spip_table_objet' => $spip_table_objet, |
|
| 564 | + 'type' => $type, |
|
| 565 | + 'id_objet' => $id, |
|
| 566 | + 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ? |
|
| 567 | + 'action' => 'controler', |
|
| 568 | + 'serveur' => $serveur, |
|
| 569 | + ), |
|
| 570 | + 'data' => $champs |
|
| 571 | + ) |
|
| 572 | + ); |
|
| 573 | + |
|
| 574 | + if (!$champs) { |
|
| 575 | + return false; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 579 | + $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_'); |
|
| 580 | + |
|
| 581 | + return $conflits; |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | |
@@ -608,63 +608,63 @@ discard block |
||
| 608 | 608 | * - post : le contenu posté |
| 609 | 609 | **/ |
| 610 | 610 | function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') { |
| 611 | - $spip_table_objet = table_objet_sql($type); |
|
| 612 | - $id_table_objet = id_table_objet($type); |
|
| 613 | - |
|
| 614 | - // Controle des MD5 envoyes |
|
| 615 | - // On elimine les donnees non modifiees par le formulaire (mais |
|
| 616 | - // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 617 | - foreach ($champs as $key => $val) { |
|
| 618 | - if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 619 | - if (is_scalar($val) and $m == md5($val)) { |
|
| 620 | - unset($champs[$key]); |
|
| 621 | - } |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - if (!$champs) { |
|
| 625 | - return; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - // On veut savoir si notre modif va avoir un impact |
|
| 629 | - // par rapport aux donnees contenues dans la base |
|
| 630 | - // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 631 | - $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 632 | - $intact = true; |
|
| 633 | - foreach ($champs as $ch => $val) { |
|
| 634 | - $intact &= ($s[$ch] == $val); |
|
| 635 | - } |
|
| 636 | - if ($intact) { |
|
| 637 | - return; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - // Detection de conflits : |
|
| 641 | - // On verifie si notre modif ne provient pas d'un formulaire |
|
| 642 | - // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 643 | - // on compare a ce qui est dans la base, et on bloque en cas |
|
| 644 | - // de conflit. |
|
| 645 | - $ctrh = $ctrq = $conflits = array(); |
|
| 646 | - foreach (array_keys($champs) as $key) { |
|
| 647 | - if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 648 | - $ctrh[$key] = $m; |
|
| 649 | - $ctrq[] = $key; |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - if ($ctrq) { |
|
| 653 | - $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 654 | - foreach ($ctrh as $key => $m) { |
|
| 655 | - if ($m != md5($ctrq[$key]) |
|
| 656 | - and $champs[$key] !== $ctrq[$key] |
|
| 657 | - ) { |
|
| 658 | - $conflits[$key] = array( |
|
| 659 | - 'base' => $ctrq[$key], |
|
| 660 | - 'post' => $champs[$key] |
|
| 661 | - ); |
|
| 662 | - unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - return $conflits; |
|
| 611 | + $spip_table_objet = table_objet_sql($type); |
|
| 612 | + $id_table_objet = id_table_objet($type); |
|
| 613 | + |
|
| 614 | + // Controle des MD5 envoyes |
|
| 615 | + // On elimine les donnees non modifiees par le formulaire (mais |
|
| 616 | + // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 617 | + foreach ($champs as $key => $val) { |
|
| 618 | + if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 619 | + if (is_scalar($val) and $m == md5($val)) { |
|
| 620 | + unset($champs[$key]); |
|
| 621 | + } |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + if (!$champs) { |
|
| 625 | + return; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + // On veut savoir si notre modif va avoir un impact |
|
| 629 | + // par rapport aux donnees contenues dans la base |
|
| 630 | + // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 631 | + $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 632 | + $intact = true; |
|
| 633 | + foreach ($champs as $ch => $val) { |
|
| 634 | + $intact &= ($s[$ch] == $val); |
|
| 635 | + } |
|
| 636 | + if ($intact) { |
|
| 637 | + return; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + // Detection de conflits : |
|
| 641 | + // On verifie si notre modif ne provient pas d'un formulaire |
|
| 642 | + // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 643 | + // on compare a ce qui est dans la base, et on bloque en cas |
|
| 644 | + // de conflit. |
|
| 645 | + $ctrh = $ctrq = $conflits = array(); |
|
| 646 | + foreach (array_keys($champs) as $key) { |
|
| 647 | + if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 648 | + $ctrh[$key] = $m; |
|
| 649 | + $ctrq[] = $key; |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + if ($ctrq) { |
|
| 653 | + $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 654 | + foreach ($ctrh as $key => $m) { |
|
| 655 | + if ($m != md5($ctrq[$key]) |
|
| 656 | + and $champs[$key] !== $ctrq[$key] |
|
| 657 | + ) { |
|
| 658 | + $conflits[$key] = array( |
|
| 659 | + 'base' => $ctrq[$key], |
|
| 660 | + 'post' => $champs[$key] |
|
| 661 | + ); |
|
| 662 | + unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + return $conflits; |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | /** |
@@ -676,11 +676,11 @@ discard block |
||
| 676 | 676 | * @return string |
| 677 | 677 | */ |
| 678 | 678 | function display_conflit_champ($x) { |
| 679 | - if (strstr($x, "\n") or strlen($x) > 80) { |
|
| 680 | - return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 681 | - } else { |
|
| 682 | - return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 683 | - } |
|
| 679 | + if (strstr($x, "\n") or strlen($x) > 80) { |
|
| 680 | + return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 681 | + } else { |
|
| 682 | + return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 683 | + } |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | /** |
@@ -698,57 +698,57 @@ discard block |
||
| 698 | 698 | * @return string |
| 699 | 699 | */ |
| 700 | 700 | function signaler_conflits_edition($conflits, $redirect = '') { |
| 701 | - include_spip('inc/minipres'); |
|
| 702 | - include_spip('inc/revisions'); |
|
| 703 | - include_spip('afficher_diff/champ'); |
|
| 704 | - include_spip('inc/suivi_versions'); |
|
| 705 | - include_spip('inc/diff'); |
|
| 706 | - $diffs = array(); |
|
| 707 | - foreach ($conflits as $champ => $a) { |
|
| 708 | - // probleme de stockage ou conflit d'edition ? |
|
| 709 | - $base = isset($a['save']) ? $a['save'] : $a['base']; |
|
| 710 | - |
|
| 711 | - $diff = new Diff(new DiffTexte); |
|
| 712 | - $n = preparer_diff($a['post']); |
|
| 713 | - $o = preparer_diff($base); |
|
| 714 | - $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o)))); |
|
| 715 | - |
|
| 716 | - $titre = isset($a['save']) ? _L( |
|
| 717 | - 'Echec lors de l\'enregistrement du champ @champ@', |
|
| 718 | - array('champ' => $champ) |
|
| 719 | - ) : $champ; |
|
| 720 | - |
|
| 721 | - $diffs[] = "<h2>$titre</h2>\n" |
|
| 722 | - . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n" |
|
| 723 | - . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n" |
|
| 724 | - . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>' |
|
| 725 | - . display_conflit_champ($a['post']) |
|
| 726 | - . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>' |
|
| 727 | - . display_conflit_champ($base); |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - if ($redirect) { |
|
| 731 | - $id = uniqid(rand()); |
|
| 732 | - $redirect = "<form action='$redirect' method='get' |
|
| 701 | + include_spip('inc/minipres'); |
|
| 702 | + include_spip('inc/revisions'); |
|
| 703 | + include_spip('afficher_diff/champ'); |
|
| 704 | + include_spip('inc/suivi_versions'); |
|
| 705 | + include_spip('inc/diff'); |
|
| 706 | + $diffs = array(); |
|
| 707 | + foreach ($conflits as $champ => $a) { |
|
| 708 | + // probleme de stockage ou conflit d'edition ? |
|
| 709 | + $base = isset($a['save']) ? $a['save'] : $a['base']; |
|
| 710 | + |
|
| 711 | + $diff = new Diff(new DiffTexte); |
|
| 712 | + $n = preparer_diff($a['post']); |
|
| 713 | + $o = preparer_diff($base); |
|
| 714 | + $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o)))); |
|
| 715 | + |
|
| 716 | + $titre = isset($a['save']) ? _L( |
|
| 717 | + 'Echec lors de l\'enregistrement du champ @champ@', |
|
| 718 | + array('champ' => $champ) |
|
| 719 | + ) : $champ; |
|
| 720 | + |
|
| 721 | + $diffs[] = "<h2>$titre</h2>\n" |
|
| 722 | + . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n" |
|
| 723 | + . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n" |
|
| 724 | + . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>' |
|
| 725 | + . display_conflit_champ($a['post']) |
|
| 726 | + . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>' |
|
| 727 | + . display_conflit_champ($base); |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + if ($redirect) { |
|
| 731 | + $id = uniqid(rand()); |
|
| 732 | + $redirect = "<form action='$redirect' method='get' |
|
| 733 | 733 | id='$id' |
| 734 | 734 | style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n" |
| 735 | - . form_hidden($redirect) |
|
| 736 | - . "<input type='submit' value='" . _T('icone_retour') . "' /> |
|
| 735 | + . form_hidden($redirect) |
|
| 736 | + . "<input type='submit' value='" . _T('icone_retour') . "' /> |
|
| 737 | 737 | </form>\n"; |
| 738 | 738 | |
| 739 | - // pour les documents, on est probablement en ajax : il faut ajaxer |
|
| 740 | - if (_AJAX) { |
|
| 741 | - $redirect .= '<script type="text/javascript">' |
|
| 742 | - . 'setTimeout(function(){$("#' . $id . '") |
|
| 739 | + // pour les documents, on est probablement en ajax : il faut ajaxer |
|
| 740 | + if (_AJAX) { |
|
| 741 | + $redirect .= '<script type="text/javascript">' |
|
| 742 | + . 'setTimeout(function(){$("#' . $id . '") |
|
| 743 | 743 | .ajaxForm({target:$("#' . $id . '").parent()}); |
| 744 | 744 | }, 200);' |
| 745 | - . "</script>\n"; |
|
| 746 | - } |
|
| 747 | - } |
|
| 745 | + . "</script>\n"; |
|
| 746 | + } |
|
| 747 | + } |
|
| 748 | 748 | |
| 749 | - echo minipres( |
|
| 750 | - _T('titre_conflit_edition'), |
|
| 751 | - '<style> |
|
| 749 | + echo minipres( |
|
| 750 | + _T('titre_conflit_edition'), |
|
| 751 | + '<style> |
|
| 752 | 752 | .diff-para-deplace { background: #e8e8ff; } |
| 753 | 753 | .diff-para-ajoute { background: #d0ffc0; color: #000; } |
| 754 | 754 | .diff-para-supprime { background: #ffd0c0; color: #904040; text-decoration: line-through; } |
@@ -759,12 +759,12 @@ discard block |
||
| 759 | 759 | .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; } |
| 760 | 760 | .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; } |
| 761 | 761 | </style>' |
| 762 | - . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>' |
|
| 763 | - . '<p>' . _T('texte_conflit_edition_correction') . '</p>' |
|
| 764 | - . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>" |
|
| 765 | - . join("\n", $diffs) |
|
| 766 | - . "</div>\n" |
|
| 767 | - |
|
| 768 | - . $redirect |
|
| 769 | - ); |
|
| 762 | + . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>' |
|
| 763 | + . '<p>' . _T('texte_conflit_edition_correction') . '</p>' |
|
| 764 | + . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>" |
|
| 765 | + . join("\n", $diffs) |
|
| 766 | + . "</div>\n" |
|
| 767 | + |
|
| 768 | + . $redirect |
|
| 769 | + ); |
|
| 770 | 770 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $res['message_ok'] = _T('info_modification_enregistree'); |
| 101 | 101 | if ($retour) { |
| 102 | 102 | if (strncmp($retour, 'javascript:', 11) == 0) { |
| 103 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 103 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour, 11).'/*]]>*/</script>'; |
|
| 104 | 104 | $res['editable'] = true; |
| 105 | 105 | } else { |
| 106 | 106 | $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | if (!isset($erreurs[$champ])) { |
| 141 | 141 | $erreurs[$champ] = ''; |
| 142 | 142 | } |
| 143 | - $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . $conflit['base'] . '</textarea>'; |
|
| 143 | + $erreurs[$champ] .= _T('alerte_modif_info_concourante')."<br /><textarea readonly='readonly' class='forml'>".$conflit['base'].'</textarea>'; |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | } |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | // Appel direct dans un squelette |
| 215 | 215 | if (!$row) { |
| 216 | 216 | if (!$new or $lier_trad) { |
| 217 | - if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 217 | + if ($select = charger_fonction('precharger_'.$type, 'inc', true)) { |
|
| 218 | 218 | $row = $select($id, $id_parent, $lier_trad); |
| 219 | 219 | } else { |
| 220 | - $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id)); |
|
| 220 | + $row = sql_fetsel('*', $table_objet_sql, $id_table_objet.'='.intval($id)); |
|
| 221 | 221 | } |
| 222 | 222 | if (!$new) { |
| 223 | 223 | $md5 = controles_md5($row); |
@@ -287,13 +287,12 @@ discard block |
||
| 287 | 287 | unset($contexte['lang']); |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 291 | - (!$lier_trad ? '' : |
|
| 292 | - ("\n<input type='hidden' name='lier_trad' value='" . |
|
| 293 | - $lier_trad . |
|
| 294 | - "' />" . |
|
| 295 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 296 | - $config['langue'] . |
|
| 290 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n". |
|
| 291 | + (!$lier_trad ? '' : ("\n<input type='hidden' name='lier_trad' value='". |
|
| 292 | + $lier_trad. |
|
| 293 | + "' />". |
|
| 294 | + "\n<input type='hidden' name='changer_lang' value='". |
|
| 295 | + $config['langue']. |
|
| 297 | 296 | "' />")) |
| 298 | 297 | . $hidden |
| 299 | 298 | . (isset($md5) ? $md5 : ''); |
@@ -320,14 +319,14 @@ discard block |
||
| 320 | 319 | $aider = charger_fonction('aider', 'inc'); |
| 321 | 320 | if (strlen($texte) > 28 * 1024) { |
| 322 | 321 | $texte = str_replace("\r\n", "\n", $texte); |
| 323 | - $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 322 | + $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 324 | 323 | if ($pos > 0 and $pos < 32 * 1024) { |
| 325 | - $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 324 | + $debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n"; |
|
| 326 | 325 | $suite = substr($texte, $pos + 2); |
| 327 | 326 | } else { |
| 328 | - $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 327 | + $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 329 | 328 | if (!($pos > 0 and $pos < 32 * 1024)) { |
| 330 | - $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 329 | + $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 331 | 330 | $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
| 332 | 331 | } else { |
| 333 | 332 | $decalage = 1; |
@@ -357,13 +356,13 @@ discard block |
||
| 357 | 356 | } |
| 358 | 357 | |
| 359 | 358 | include_spip('inc/barre'); |
| 360 | - $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n"; |
|
| 359 | + $textes_supplement = "<br /><span style='color: red'>"._T('info_texte_long')."</span>\n"; |
|
| 361 | 360 | $nombre = 0; |
| 362 | 361 | |
| 363 | 362 | while (strlen($texte) > 29 * 1024) { |
| 364 | 363 | $nombre++; |
| 365 | 364 | list($texte1, $texte) = coupe_trop_long($texte); |
| 366 | - $textes_supplement .= '<br />' . |
|
| 365 | + $textes_supplement .= '<br />'. |
|
| 367 | 366 | "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n"; |
| 368 | 367 | } |
| 369 | 368 | |
@@ -451,7 +450,7 @@ discard block |
||
| 451 | 450 | $ctr = array(); |
| 452 | 451 | foreach ($data as $key => $val) { |
| 453 | 452 | $m = md5($val); |
| 454 | - $k = $prefixe . $key; |
|
| 453 | + $k = $prefixe.$key; |
|
| 455 | 454 | |
| 456 | 455 | switch ($format) { |
| 457 | 456 | case 'html': |
@@ -464,7 +463,7 @@ discard block |
||
| 464 | 463 | } |
| 465 | 464 | |
| 466 | 465 | if ($format == 'html') { |
| 467 | - return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n"; |
|
| 466 | + return "\n\n<!-- controles md5 -->\n".join("\n", $ctr)."\n\n"; |
|
| 468 | 467 | } else { |
| 469 | 468 | return $ctr; |
| 470 | 469 | } |
@@ -615,7 +614,7 @@ discard block |
||
| 615 | 614 | // On elimine les donnees non modifiees par le formulaire (mais |
| 616 | 615 | // potentiellement modifiees entre temps par un autre utilisateur) |
| 617 | 616 | foreach ($champs as $key => $val) { |
| 618 | - if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 617 | + if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) { |
|
| 619 | 618 | if (is_scalar($val) and $m == md5($val)) { |
| 620 | 619 | unset($champs[$key]); |
| 621 | 620 | } |
@@ -644,7 +643,7 @@ discard block |
||
| 644 | 643 | // de conflit. |
| 645 | 644 | $ctrh = $ctrq = $conflits = array(); |
| 646 | 645 | foreach (array_keys($champs) as $key) { |
| 647 | - if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 646 | + if (isset($ctr[$prefix.$key]) and $m = $ctr[$prefix.$key]) { |
|
| 648 | 647 | $ctrh[$key] = $m; |
| 649 | 648 | $ctrq[] = $key; |
| 650 | 649 | } |
@@ -677,9 +676,9 @@ discard block |
||
| 677 | 676 | */ |
| 678 | 677 | function display_conflit_champ($x) { |
| 679 | 678 | if (strstr($x, "\n") or strlen($x) > 80) { |
| 680 | - return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 679 | + return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n"; |
|
| 681 | 680 | } else { |
| 682 | - return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 681 | + return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n"; |
|
| 683 | 682 | } |
| 684 | 683 | } |
| 685 | 684 | |
@@ -719,11 +718,11 @@ discard block |
||
| 719 | 718 | ) : $champ; |
| 720 | 719 | |
| 721 | 720 | $diffs[] = "<h2>$titre</h2>\n" |
| 722 | - . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n" |
|
| 723 | - . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n" |
|
| 724 | - . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>' |
|
| 721 | + . '<h3>'._T('info_conflit_edition_differences')."</h3>\n" |
|
| 722 | + . "<div style='max-height:8em; overflow: auto; width:99%;'>".$d."</div>\n" |
|
| 723 | + . '<h4>'._T('info_conflit_edition_votre_version').'</h4>' |
|
| 725 | 724 | . display_conflit_champ($a['post']) |
| 726 | - . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>' |
|
| 725 | + . '<h4>'._T('info_conflit_edition_version_enregistree').'</h4>' |
|
| 727 | 726 | . display_conflit_champ($base); |
| 728 | 727 | } |
| 729 | 728 | |
@@ -731,16 +730,16 @@ discard block |
||
| 731 | 730 | $id = uniqid(rand()); |
| 732 | 731 | $redirect = "<form action='$redirect' method='get' |
| 733 | 732 | id='$id' |
| 734 | - style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n" |
|
| 733 | + style='float:".$GLOBALS['spip_lang_right']."; margin-top:2em;'>\n" |
|
| 735 | 734 | . form_hidden($redirect) |
| 736 | - . "<input type='submit' value='" . _T('icone_retour') . "' /> |
|
| 735 | + . "<input type='submit' value='"._T('icone_retour')."' /> |
|
| 737 | 736 | </form>\n"; |
| 738 | 737 | |
| 739 | 738 | // pour les documents, on est probablement en ajax : il faut ajaxer |
| 740 | 739 | if (_AJAX) { |
| 741 | 740 | $redirect .= '<script type="text/javascript">' |
| 742 | - . 'setTimeout(function(){$("#' . $id . '") |
|
| 743 | - .ajaxForm({target:$("#' . $id . '").parent()}); |
|
| 741 | + . 'setTimeout(function(){$("#'.$id.'") |
|
| 742 | + .ajaxForm({target:$("#' . $id.'").parent()}); |
|
| 744 | 743 | }, 200);' |
| 745 | 744 | . "</script>\n"; |
| 746 | 745 | } |
@@ -759,9 +758,9 @@ discard block |
||
| 759 | 758 | .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; } |
| 760 | 759 | .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; } |
| 761 | 760 | </style>' |
| 762 | - . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>' |
|
| 763 | - . '<p>' . _T('texte_conflit_edition_correction') . '</p>' |
|
| 764 | - . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>" |
|
| 761 | + . '<p>'._T('info_conflit_edition_avis_non_sauvegarde').'</p>' |
|
| 762 | + . '<p>'._T('texte_conflit_edition_correction').'</p>' |
|
| 763 | + . "<div style='text-align:".$GLOBALS['spip_lang_left'].";'>" |
|
| 765 | 764 | . join("\n", $diffs) |
| 766 | 765 | . "</div>\n" |
| 767 | 766 | |
@@ -187,7 +187,7 @@ |
||
| 187 | 187 | * @param string $to |
| 188 | 188 | * @param string $texte |
| 189 | 189 | * @param string $parts |
| 190 | - * @return array |
|
| 190 | + * @return string[] |
|
| 191 | 191 | */ |
| 192 | 192 | function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') { |
| 193 | 193 | $charset = $GLOBALS['meta']['charset']; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Mail |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | 34 | function nettoyer_titre_email($titre) { |
| 35 | - return str_replace("\n", ' ', textebrut(corriger_typo($titre))); |
|
| 35 | + return str_replace("\n", ' ', textebrut(corriger_typo($titre))); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -48,23 +48,23 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function nettoyer_caracteres_mail($t) { |
| 50 | 50 | |
| 51 | - $t = filtrer_entites($t); |
|
| 51 | + $t = filtrer_entites($t); |
|
| 52 | 52 | |
| 53 | - if ($GLOBALS['meta']['charset'] <> 'utf-8') { |
|
| 54 | - $t = str_replace( |
|
| 55 | - array('’', '“', '”'), |
|
| 56 | - array("'", '"', '"'), |
|
| 57 | - $t |
|
| 58 | - ); |
|
| 59 | - } |
|
| 53 | + if ($GLOBALS['meta']['charset'] <> 'utf-8') { |
|
| 54 | + $t = str_replace( |
|
| 55 | + array('’', '“', '”'), |
|
| 56 | + array("'", '"', '"'), |
|
| 57 | + $t |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $t = str_replace( |
|
| 62 | - array('—', '&endash;'), |
|
| 63 | - array('--', '-'), |
|
| 64 | - $t |
|
| 65 | - ); |
|
| 61 | + $t = str_replace( |
|
| 62 | + array('—', '&endash;'), |
|
| 63 | + array('--', '-'), |
|
| 64 | + $t |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - return $t; |
|
| 67 | + return $t; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -97,86 +97,86 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') { |
| 99 | 99 | |
| 100 | - if (!email_valide($destinataire)) { |
|
| 101 | - return false; |
|
| 102 | - } |
|
| 103 | - if ($destinataire == _T('info_mail_fournisseur')) { |
|
| 104 | - return false; |
|
| 105 | - } // tres fort |
|
| 106 | - |
|
| 107 | - // Fournir si possible un Message-Id: conforme au RFC1036, |
|
| 108 | - // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER |
|
| 109 | - |
|
| 110 | - $email_envoi = $GLOBALS['meta']['email_envoi']; |
|
| 111 | - if (!email_valide($email_envoi)) { |
|
| 112 | - spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.'); |
|
| 113 | - $email_envoi = $destinataire; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $parts = ''; |
|
| 117 | - if (is_array($corps)) { |
|
| 118 | - $texte = $corps['texte']; |
|
| 119 | - $from = (isset($corps['from']) ? $corps['from'] : $from); |
|
| 120 | - $headers = (isset($corps['headers']) ? $corps['headers'] : $headers); |
|
| 121 | - if (is_array($headers)) { |
|
| 122 | - $headers = implode("\n", $headers); |
|
| 123 | - } |
|
| 124 | - if ($corps['pieces_jointes'] and function_exists('mail_embarquer_pieces_jointes')) { |
|
| 125 | - $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']); |
|
| 126 | - } |
|
| 127 | - } else { |
|
| 128 | - $texte = $corps; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - if (!$from) { |
|
| 132 | - $from = $email_envoi; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin |
|
| 136 | - if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) { |
|
| 137 | - $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')'; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // nettoyer les é ’, &emdash; etc... |
|
| 141 | - // les 'cliquer ici' etc sont a eviter; voir: |
|
| 142 | - // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf |
|
| 143 | - $texte = nettoyer_caracteres_mail($texte); |
|
| 144 | - $sujet = nettoyer_caracteres_mail($sujet); |
|
| 145 | - |
|
| 146 | - // encoder le sujet si possible selon la RFC |
|
| 147 | - if (init_mb_string()) { |
|
| 148 | - # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne |
|
| 149 | - # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian) |
|
| 150 | - $charset = $GLOBALS['meta']['charset']; |
|
| 151 | - mb_internal_encoding($charset); |
|
| 152 | - $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n"); |
|
| 153 | - mb_internal_encoding('utf-8'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) { |
|
| 157 | - $texte = wordwrap($texte); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts); |
|
| 161 | - |
|
| 162 | - if (_OS_SERVEUR == 'windows') { |
|
| 163 | - $texte = preg_replace("@\r*\n@", "\r\n", $texte); |
|
| 164 | - $headers = preg_replace("@\r*\n@", "\r\n", $headers); |
|
| 165 | - $sujet = preg_replace("@\r*\n@", "\r\n", $sujet); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - spip_log("mail $destinataire\n$sujet\n$headers", 'mails'); |
|
| 169 | - // mode TEST : forcer l'email |
|
| 170 | - if (defined('_TEST_EMAIL_DEST')) { |
|
| 171 | - if (!_TEST_EMAIL_DEST) { |
|
| 172 | - return false; |
|
| 173 | - } else { |
|
| 174 | - $texte = "Dest : $destinataire\r\n" . $texte; |
|
| 175 | - $destinataire = _TEST_EMAIL_DEST; |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return @mail($destinataire, $sujet, $texte, $headers); |
|
| 100 | + if (!email_valide($destinataire)) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | + if ($destinataire == _T('info_mail_fournisseur')) { |
|
| 104 | + return false; |
|
| 105 | + } // tres fort |
|
| 106 | + |
|
| 107 | + // Fournir si possible un Message-Id: conforme au RFC1036, |
|
| 108 | + // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER |
|
| 109 | + |
|
| 110 | + $email_envoi = $GLOBALS['meta']['email_envoi']; |
|
| 111 | + if (!email_valide($email_envoi)) { |
|
| 112 | + spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.'); |
|
| 113 | + $email_envoi = $destinataire; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $parts = ''; |
|
| 117 | + if (is_array($corps)) { |
|
| 118 | + $texte = $corps['texte']; |
|
| 119 | + $from = (isset($corps['from']) ? $corps['from'] : $from); |
|
| 120 | + $headers = (isset($corps['headers']) ? $corps['headers'] : $headers); |
|
| 121 | + if (is_array($headers)) { |
|
| 122 | + $headers = implode("\n", $headers); |
|
| 123 | + } |
|
| 124 | + if ($corps['pieces_jointes'] and function_exists('mail_embarquer_pieces_jointes')) { |
|
| 125 | + $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']); |
|
| 126 | + } |
|
| 127 | + } else { |
|
| 128 | + $texte = $corps; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + if (!$from) { |
|
| 132 | + $from = $email_envoi; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin |
|
| 136 | + if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) { |
|
| 137 | + $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')'; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // nettoyer les é ’, &emdash; etc... |
|
| 141 | + // les 'cliquer ici' etc sont a eviter; voir: |
|
| 142 | + // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf |
|
| 143 | + $texte = nettoyer_caracteres_mail($texte); |
|
| 144 | + $sujet = nettoyer_caracteres_mail($sujet); |
|
| 145 | + |
|
| 146 | + // encoder le sujet si possible selon la RFC |
|
| 147 | + if (init_mb_string()) { |
|
| 148 | + # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne |
|
| 149 | + # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian) |
|
| 150 | + $charset = $GLOBALS['meta']['charset']; |
|
| 151 | + mb_internal_encoding($charset); |
|
| 152 | + $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n"); |
|
| 153 | + mb_internal_encoding('utf-8'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) { |
|
| 157 | + $texte = wordwrap($texte); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + list($headers, $texte) = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts); |
|
| 161 | + |
|
| 162 | + if (_OS_SERVEUR == 'windows') { |
|
| 163 | + $texte = preg_replace("@\r*\n@", "\r\n", $texte); |
|
| 164 | + $headers = preg_replace("@\r*\n@", "\r\n", $headers); |
|
| 165 | + $sujet = preg_replace("@\r*\n@", "\r\n", $sujet); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + spip_log("mail $destinataire\n$sujet\n$headers", 'mails'); |
|
| 169 | + // mode TEST : forcer l'email |
|
| 170 | + if (defined('_TEST_EMAIL_DEST')) { |
|
| 171 | + if (!_TEST_EMAIL_DEST) { |
|
| 172 | + return false; |
|
| 173 | + } else { |
|
| 174 | + $texte = "Dest : $destinataire\r\n" . $texte; |
|
| 175 | + $destinataire = _TEST_EMAIL_DEST; |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return @mail($destinataire, $sujet, $texte, $headers); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -190,52 +190,52 @@ discard block |
||
| 190 | 190 | * @return array |
| 191 | 191 | */ |
| 192 | 192 | function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') { |
| 193 | - $charset = $GLOBALS['meta']['charset']; |
|
| 194 | - |
|
| 195 | - // Ajouter le Content-Type et consort s'il n'y est pas deja |
|
| 196 | - if (strpos($headers, 'Content-Type: ') === false) { |
|
| 197 | - $type = |
|
| 198 | - "Content-Type: text/plain;charset=\"$charset\";\n" . |
|
| 199 | - "Content-Transfer-Encoding: 8bit\n"; |
|
| 200 | - } else { |
|
| 201 | - $type = ''; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // calculer un identifiant unique |
|
| 205 | - preg_match('/@\S+/', $from, $domain); |
|
| 206 | - $uniq = rand() . '_' . md5($to . $texte) . $domain[0]; |
|
| 207 | - |
|
| 208 | - // Si multi-part, s'en servir comme borne ... |
|
| 209 | - if ($parts) { |
|
| 210 | - $texte = "--$uniq\n$type\n" . $texte . "\n"; |
|
| 211 | - foreach ($parts as $part) { |
|
| 212 | - $n = strlen($part[1]) . ($part[0] ? "\n" : ''); |
|
| 213 | - $e = join("\n", $part[0]); |
|
| 214 | - $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1]; |
|
| 215 | - } |
|
| 216 | - $texte .= "\n\n--$uniq--\n"; |
|
| 217 | - // Si boundary n'est pas entre guillemets, |
|
| 218 | - // elle est comprise mais le charset est ignoree ! |
|
| 219 | - $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n"; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // .. et s'en servir pour plaire a SpamAssassin |
|
| 223 | - |
|
| 224 | - $mid = 'Message-Id: <' . $uniq . '>'; |
|
| 225 | - |
|
| 226 | - // indispensable pour les sites qui collent d'office From: serveur-http |
|
| 227 | - // sauf si deja mis par l'envoyeur |
|
| 228 | - $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n"; |
|
| 229 | - |
|
| 230 | - // Nettoyer les en-tetes envoyees |
|
| 231 | - // Ajouter le \n final |
|
| 232 | - if (strlen($headers = trim($headers))) { |
|
| 233 | - $headers .= "\n"; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // Et mentionner l'indeboulonable nomenclature ratee |
|
| 237 | - |
|
| 238 | - $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n"; |
|
| 239 | - |
|
| 240 | - return array($headers, $texte); |
|
| 193 | + $charset = $GLOBALS['meta']['charset']; |
|
| 194 | + |
|
| 195 | + // Ajouter le Content-Type et consort s'il n'y est pas deja |
|
| 196 | + if (strpos($headers, 'Content-Type: ') === false) { |
|
| 197 | + $type = |
|
| 198 | + "Content-Type: text/plain;charset=\"$charset\";\n" . |
|
| 199 | + "Content-Transfer-Encoding: 8bit\n"; |
|
| 200 | + } else { |
|
| 201 | + $type = ''; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // calculer un identifiant unique |
|
| 205 | + preg_match('/@\S+/', $from, $domain); |
|
| 206 | + $uniq = rand() . '_' . md5($to . $texte) . $domain[0]; |
|
| 207 | + |
|
| 208 | + // Si multi-part, s'en servir comme borne ... |
|
| 209 | + if ($parts) { |
|
| 210 | + $texte = "--$uniq\n$type\n" . $texte . "\n"; |
|
| 211 | + foreach ($parts as $part) { |
|
| 212 | + $n = strlen($part[1]) . ($part[0] ? "\n" : ''); |
|
| 213 | + $e = join("\n", $part[0]); |
|
| 214 | + $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1]; |
|
| 215 | + } |
|
| 216 | + $texte .= "\n\n--$uniq--\n"; |
|
| 217 | + // Si boundary n'est pas entre guillemets, |
|
| 218 | + // elle est comprise mais le charset est ignoree ! |
|
| 219 | + $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n"; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // .. et s'en servir pour plaire a SpamAssassin |
|
| 223 | + |
|
| 224 | + $mid = 'Message-Id: <' . $uniq . '>'; |
|
| 225 | + |
|
| 226 | + // indispensable pour les sites qui collent d'office From: serveur-http |
|
| 227 | + // sauf si deja mis par l'envoyeur |
|
| 228 | + $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n"; |
|
| 229 | + |
|
| 230 | + // Nettoyer les en-tetes envoyees |
|
| 231 | + // Ajouter le \n final |
|
| 232 | + if (strlen($headers = trim($headers))) { |
|
| 233 | + $headers .= "\n"; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // Et mentionner l'indeboulonable nomenclature ratee |
|
| 237 | + |
|
| 238 | + $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n"; |
|
| 239 | + |
|
| 240 | + return array($headers, $texte); |
|
| 241 | 241 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin |
| 136 | 136 | if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) { |
| 137 | - $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')'; |
|
| 137 | + $from .= ' ('.str_replace(')', '', translitteration(str_replace('@', ' at ', $from))).')'; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // nettoyer les é ’, &emdash; etc... |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | if (!_TEST_EMAIL_DEST) { |
| 172 | 172 | return false; |
| 173 | 173 | } else { |
| 174 | - $texte = "Dest : $destinataire\r\n" . $texte; |
|
| 174 | + $texte = "Dest : $destinataire\r\n".$texte; |
|
| 175 | 175 | $destinataire = _TEST_EMAIL_DEST; |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | // Ajouter le Content-Type et consort s'il n'y est pas deja |
| 196 | 196 | if (strpos($headers, 'Content-Type: ') === false) { |
| 197 | 197 | $type = |
| 198 | - "Content-Type: text/plain;charset=\"$charset\";\n" . |
|
| 198 | + "Content-Type: text/plain;charset=\"$charset\";\n". |
|
| 199 | 199 | "Content-Transfer-Encoding: 8bit\n"; |
| 200 | 200 | } else { |
| 201 | 201 | $type = ''; |
@@ -203,15 +203,15 @@ discard block |
||
| 203 | 203 | |
| 204 | 204 | // calculer un identifiant unique |
| 205 | 205 | preg_match('/@\S+/', $from, $domain); |
| 206 | - $uniq = rand() . '_' . md5($to . $texte) . $domain[0]; |
|
| 206 | + $uniq = rand().'_'.md5($to.$texte).$domain[0]; |
|
| 207 | 207 | |
| 208 | 208 | // Si multi-part, s'en servir comme borne ... |
| 209 | 209 | if ($parts) { |
| 210 | - $texte = "--$uniq\n$type\n" . $texte . "\n"; |
|
| 210 | + $texte = "--$uniq\n$type\n".$texte."\n"; |
|
| 211 | 211 | foreach ($parts as $part) { |
| 212 | - $n = strlen($part[1]) . ($part[0] ? "\n" : ''); |
|
| 212 | + $n = strlen($part[1]).($part[0] ? "\n" : ''); |
|
| 213 | 213 | $e = join("\n", $part[0]); |
| 214 | - $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1]; |
|
| 214 | + $texte .= "\n--$uniq\nContent-Length: $n$e\n\n".$part[1]; |
|
| 215 | 215 | } |
| 216 | 216 | $texte .= "\n\n--$uniq--\n"; |
| 217 | 217 | // Si boundary n'est pas entre guillemets, |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | |
| 222 | 222 | // .. et s'en servir pour plaire a SpamAssassin |
| 223 | 223 | |
| 224 | - $mid = 'Message-Id: <' . $uniq . '>'; |
|
| 224 | + $mid = 'Message-Id: <'.$uniq.'>'; |
|
| 225 | 225 | |
| 226 | 226 | // indispensable pour les sites qui collent d'office From: serveur-http |
| 227 | 227 | // sauf si deja mis par l'envoyeur |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @param string $fonc |
| 71 | 71 | * Nom du filtre |
| 72 | - * @param null $default |
|
| 72 | + * @param string $default |
|
| 73 | 73 | * Nom du filtre appliqué par défaut si celui demandé n'est pas trouvé |
| 74 | 74 | * @return string |
| 75 | 75 | * Fonction PHP correspondante du filtre demandé |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @see filtrer() Assez proche |
| 118 | 118 | * |
| 119 | - * @param mixed $arg |
|
| 119 | + * @param string $arg |
|
| 120 | 120 | * Texte (le plus souvent) sur lequel appliquer le filtre |
| 121 | 121 | * @param string $filtre |
| 122 | 122 | * Nom du filtre à appliquer |
@@ -673,7 +673,7 @@ discard block |
||
| 673 | 673 | * corriger toutes les `&xx;` en `&xx;` |
| 674 | 674 | * @param bool $quote |
| 675 | 675 | * Échapper aussi les simples quotes en `'` |
| 676 | - * @return mixed|string |
|
| 676 | + * @return string |
|
| 677 | 677 | */ |
| 678 | 678 | function entites_html($texte, $tout = false, $quote = true) { |
| 679 | 679 | if (!is_string($texte) or !$texte |
@@ -1310,7 +1310,7 @@ discard block |
||
| 1310 | 1310 | * |
| 1311 | 1311 | * @param mixed $texte |
| 1312 | 1312 | * Contenu de reference a tester |
| 1313 | - * @param mixed $sinon |
|
| 1313 | + * @param string|null $sinon |
|
| 1314 | 1314 | * Contenu a retourner si le contenu de reference est vide |
| 1315 | 1315 | * @return mixed |
| 1316 | 1316 | * Retourne $texte, sinon $sinon. |
@@ -1568,7 +1568,7 @@ discard block |
||
| 1568 | 1568 | * @param string $letexte |
| 1569 | 1569 | * @param string $lang |
| 1570 | 1570 | * Langue à retrouver (si vide, utilise la langue en cours). |
| 1571 | - * @param array $options Options { |
|
| 1571 | + * @param boolean $options Options { |
|
| 1572 | 1572 | * @type bool $echappe_span |
| 1573 | 1573 | * True pour échapper les balises span (false par défaut) |
| 1574 | 1574 | * @type string $lang_defaut |
@@ -1658,7 +1658,7 @@ discard block |
||
| 1658 | 1658 | * @param string $letexte |
| 1659 | 1659 | * @param string $lang |
| 1660 | 1660 | * Langue à retrouver (si vide, utilise la langue en cours). |
| 1661 | - * @param array $options Options { |
|
| 1661 | + * @param boolean $options Options { |
|
| 1662 | 1662 | * @type bool $echappe_span |
| 1663 | 1663 | * True pour échapper les balises span (false par défaut) |
| 1664 | 1664 | * @type string $lang_defaut |
@@ -2042,6 +2042,9 @@ discard block |
||
| 2042 | 2042 | // Quelques fonctions de calcul arithmetique |
| 2043 | 2043 | // |
| 2044 | 2044 | function floatstr($a) { return str_replace(',','.',(string)floatval($a)); } |
| 2045 | +/** |
|
| 2046 | + * @param string $f |
|
| 2047 | + */ |
|
| 2045 | 2048 | function strize($f, $a, $b) { return floatstr($f(floatstr($a),floatstr($b))); } |
| 2046 | 2049 | |
| 2047 | 2050 | /** |
@@ -2184,7 +2187,7 @@ discard block |
||
| 2184 | 2187 | * |
| 2185 | 2188 | * @param string $adresses |
| 2186 | 2189 | * Adresse ou liste d'adresse |
| 2187 | - * @return bool|string |
|
| 2190 | + * @return false|string |
|
| 2188 | 2191 | * - false si pas conforme, |
| 2189 | 2192 | * - la normalisation de la dernière adresse donnée sinon |
| 2190 | 2193 | **/ |
@@ -2518,7 +2521,7 @@ discard block |
||
| 2518 | 2521 | * @param int $a |
| 2519 | 2522 | * @param int $b |
| 2520 | 2523 | * @param int $c |
| 2521 | - * @return int |
|
| 2524 | + * @return double |
|
| 2522 | 2525 | * Retourne `$a*$b/$c` |
| 2523 | 2526 | **/ |
| 2524 | 2527 | function regledetrois($a, $b, $c) { |
@@ -4551,7 +4554,7 @@ discard block |
||
| 4551 | 4554 | * Nombre d'éléments |
| 4552 | 4555 | * @param string $objet |
| 4553 | 4556 | * Objet |
| 4554 | - * @return mixed|string |
|
| 4557 | + * @return string |
|
| 4555 | 4558 | * Texte traduit du comptage, tel que '3 articles' |
| 4556 | 4559 | */ |
| 4557 | 4560 | function objet_afficher_nb($nb, $objet) { |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | return $f; |
| 94 | 94 | } |
| 95 | - foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) { |
|
| 95 | + foreach (array('filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc) as $f) { |
|
| 96 | 96 | trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
| 97 | 97 | // fonction ou name\space\fonction |
| 98 | 98 | if (is_callable($f)) { |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | function spip_version() { |
| 160 | 160 | $version = $GLOBALS['spip_version_affichee']; |
| 161 | 161 | if ($svn_revision = version_svn_courante(_DIR_RACINE)) { |
| 162 | - $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 162 | + $version .= ($svn_revision < 0 ? ' SVN' : '').' ['.abs($svn_revision).']'; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | return $version; |
@@ -186,15 +186,15 @@ discard block |
||
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // version installee par paquet ZIP |
| 189 | - if (lire_fichier($dir . '/svn.revision', $c) |
|
| 189 | + if (lire_fichier($dir.'/svn.revision', $c) |
|
| 190 | 190 | and preg_match(',Revision: (\d+),', $c, $d) |
| 191 | 191 | ) { |
| 192 | 192 | return intval($d[1]); |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // version installee par SVN |
| 196 | - if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 197 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 196 | + if (file_exists($dir.'/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 197 | + $db = new SQLite3($dir.'/.svn/wc.db'); |
|
| 198 | 198 | $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
| 199 | 199 | if ($result) { |
| 200 | 200 | $row = $result->fetchArray(); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | return -$row['changed_revision']; |
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | - } else if (lire_fichier($dir . '/.svn/entries', $c) |
|
| 205 | + } else if (lire_fichier($dir.'/.svn/entries', $c) |
|
| 206 | 206 | and ( |
| 207 | 207 | (preg_match_all( |
| 208 | 208 | ',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER) |
@@ -222,11 +222,11 @@ discard block |
||
| 222 | 222 | |
| 223 | 223 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
| 224 | 224 | // et laisser passer les fonctions personnelles baptisees image_... |
| 225 | -$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php'; |
|
| 226 | -$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php'; |
|
| 227 | -$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php'; |
|
| 228 | -$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php'; |
|
| 229 | -$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php'; |
|
| 225 | +$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php'; |
|
| 226 | +$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php'; |
|
| 227 | +$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php'; |
|
| 228 | +$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php'; |
|
| 229 | +$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php'; |
|
| 230 | 230 | |
| 231 | 231 | $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php'; |
| 232 | 232 | $GLOBALS['spip_matrice']['couleur_foncer'] = 'inc/filtres_images_mini.php'; |
@@ -372,8 +372,8 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | function filtre_debug($val, $key = null) { |
| 374 | 374 | $debug = ( |
| 375 | - is_null($key) ? '' : (var_export($key, true) . " = ") |
|
| 376 | - ) . var_export($val, true); |
|
| 375 | + is_null($key) ? '' : (var_export($key, true)." = ") |
|
| 376 | + ).var_export($val, true); |
|
| 377 | 377 | |
| 378 | 378 | include_spip('inc/autoriser'); |
| 379 | 379 | if (autoriser('webmestre')) { |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
| 462 | 462 | $srcover = $match[1]; |
| 463 | 463 | array_shift($args); |
| 464 | - array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 464 | + array_unshift($args, "<img src='".$match[1]."' />"); |
|
| 465 | 465 | $srcover_filter = call_user_func_array($filtre, $args); |
| 466 | 466 | $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
| 467 | 467 | $reduit = str_replace($srcover, $srcover_filter, $reduit); |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | // " -> " et tout ce genre de choses |
| 812 | 812 | $u = $GLOBALS['meta']['pcre_u']; |
| 813 | 813 | $texte = str_replace(" ", " ", $texte); |
| 814 | - $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte); |
|
| 814 | + $texte = preg_replace('/\s{2,}/S'.$u, " ", $texte); |
|
| 815 | 815 | // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
| 816 | 816 | $texte = entites_html($texte, false, false); |
| 817 | 817 | // mais bien echapper les double quotes ! |
@@ -871,7 +871,7 @@ discard block |
||
| 871 | 871 | **/ |
| 872 | 872 | function supprimer_numero($texte) { |
| 873 | 873 | return preg_replace( |
| 874 | - ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 874 | + ",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S", |
|
| 875 | 875 | "", $texte); |
| 876 | 876 | } |
| 877 | 877 | |
@@ -896,7 +896,7 @@ discard block |
||
| 896 | 896 | **/ |
| 897 | 897 | function recuperer_numero($texte) { |
| 898 | 898 | if (preg_match( |
| 899 | - ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 899 | + ",^[[:space:]]*([0-9]+)([.)]|".chr(194).'?'.chr(176).")[[:space:]]+,S", |
|
| 900 | 900 | $texte, $regs)) { |
| 901 | 901 | return strval($regs[1]); |
| 902 | 902 | } else { |
@@ -981,8 +981,8 @@ discard block |
||
| 981 | 981 | **/ |
| 982 | 982 | function textebrut($texte) { |
| 983 | 983 | $u = $GLOBALS['meta']['pcre_u']; |
| 984 | - $texte = preg_replace('/\s+/S' . $u, " ", $texte); |
|
| 985 | - $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte); |
|
| 984 | + $texte = preg_replace('/\s+/S'.$u, " ", $texte); |
|
| 985 | + $texte = preg_replace("/<(p|br)( [^>]*)?".">/iS", "\n\n", $texte); |
|
| 986 | 986 | $texte = preg_replace("/^\n+/", "", $texte); |
| 987 | 987 | $texte = preg_replace("/\n+$/", "", $texte); |
| 988 | 988 | $texte = preg_replace("/\n +/", "\n", $texte); |
@@ -1010,7 +1010,7 @@ discard block |
||
| 1010 | 1010 | if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
| 1011 | 1011 | $texte, $liens, PREG_SET_ORDER)) { |
| 1012 | 1012 | foreach ($liens[0] as $a) { |
| 1013 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1013 | + $rel = 'noopener noreferrer '.extraire_attribut($a, 'rel'); |
|
| 1014 | 1014 | $ablank = inserer_attribut($a, 'rel', $rel); |
| 1015 | 1015 | $ablank = inserer_attribut($ablank, 'target', '_blank'); |
| 1016 | 1016 | $texte = str_replace($a, $ablank, $texte); |
@@ -1035,7 +1035,7 @@ discard block |
||
| 1035 | 1035 | foreach ($regs[0] as $a) { |
| 1036 | 1036 | $rel = extraire_attribut($a, "rel"); |
| 1037 | 1037 | if (strpos($rel, "nofollow") === false) { |
| 1038 | - $rel = "nofollow" . ($rel ? " $rel" : ""); |
|
| 1038 | + $rel = "nofollow".($rel ? " $rel" : ""); |
|
| 1039 | 1039 | $anofollow = inserer_attribut($a, "rel", $rel); |
| 1040 | 1040 | $texte = str_replace($a, $anofollow, $texte); |
| 1041 | 1041 | } |
@@ -1064,7 +1064,7 @@ discard block |
||
| 1064 | 1064 | $u = $GLOBALS['meta']['pcre_u']; |
| 1065 | 1065 | $texte = preg_replace("@</p>@iS", "\n", $texte); |
| 1066 | 1066 | $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte); |
| 1067 | - $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte); |
|
| 1067 | + $texte = preg_replace("@^\s*<br />@S".$u, "", $texte); |
|
| 1068 | 1068 | |
| 1069 | 1069 | return $texte; |
| 1070 | 1070 | } |
@@ -1094,7 +1094,7 @@ discard block |
||
| 1094 | 1094 | return $texte; |
| 1095 | 1095 | } |
| 1096 | 1096 | include_spip('inc/texte'); |
| 1097 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1097 | + $tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ? |
|
| 1098 | 1098 | 'div' : 'span'; |
| 1099 | 1099 | |
| 1100 | 1100 | return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
@@ -1203,7 +1203,7 @@ discard block |
||
| 1203 | 1203 | function attribut_html($texte, $textebrut = true) { |
| 1204 | 1204 | $u = $GLOBALS['meta']['pcre_u']; |
| 1205 | 1205 | if ($textebrut) { |
| 1206 | - $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte)); |
|
| 1206 | + $texte = preg_replace(array(",\n,", ",\s(?=\s),msS".$u), array(" ", ""), textebrut($texte)); |
|
| 1207 | 1207 | } |
| 1208 | 1208 | $texte = texte_backend($texte); |
| 1209 | 1209 | $texte = str_replace(array("'", '"'), array(''', '"'), $texte); |
@@ -1232,7 +1232,7 @@ discard block |
||
| 1232 | 1232 | # un message pour abs_url |
| 1233 | 1233 | $GLOBALS['mode_abs_url'] = 'url'; |
| 1234 | 1234 | $url = trim($url); |
| 1235 | - $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1235 | + $r = ",^(?:"._PROTOCOLES_STD.'):?/?/?$,iS'; |
|
| 1236 | 1236 | |
| 1237 | 1237 | return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
| 1238 | 1238 | } |
@@ -1434,14 +1434,14 @@ discard block |
||
| 1434 | 1434 | if (strpos($texte, "<") !== false) { |
| 1435 | 1435 | include_spip('inc/lien'); |
| 1436 | 1436 | if (defined('_PREG_MODELE')) { |
| 1437 | - $preg_modeles = "@" . _PREG_MODELE . "@imsS"; |
|
| 1437 | + $preg_modeles = "@"._PREG_MODELE."@imsS"; |
|
| 1438 | 1438 | $texte = echappe_html($texte, '', true, $preg_modeles); |
| 1439 | 1439 | } |
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | 1442 | $debut = ''; |
| 1443 | 1443 | $suite = $texte; |
| 1444 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1444 | + while ($t = strpos('-'.$suite, "\n", 1)) { |
|
| 1445 | 1445 | $debut .= substr($suite, 0, $t - 1); |
| 1446 | 1446 | $suite = substr($suite, $t); |
| 1447 | 1447 | $car = substr($suite, 0, 1); |
@@ -1458,11 +1458,11 @@ discard block |
||
| 1458 | 1458 | $suite = substr($suite, strlen($regs[0])); |
| 1459 | 1459 | } |
| 1460 | 1460 | } |
| 1461 | - $texte = $debut . $suite; |
|
| 1461 | + $texte = $debut.$suite; |
|
| 1462 | 1462 | |
| 1463 | 1463 | $texte = echappe_retour($texte); |
| 1464 | 1464 | |
| 1465 | - return $texte . $fin; |
|
| 1465 | + return $texte.$fin; |
|
| 1466 | 1466 | } |
| 1467 | 1467 | |
| 1468 | 1468 | |
@@ -1523,7 +1523,7 @@ discard block |
||
| 1523 | 1523 | } |
| 1524 | 1524 | |
| 1525 | 1525 | foreach ($regs as $reg) { |
| 1526 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1526 | + $cle = ($reg[1] ? $reg[1].':' : '').$reg[2]; |
|
| 1527 | 1527 | $desc = $traduire($cle, $lang, true); |
| 1528 | 1528 | $l = $desc->langue; |
| 1529 | 1529 | // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
@@ -1636,7 +1636,7 @@ discard block |
||
| 1636 | 1636 | // il ne faut pas echapper en div si propre produit un seul paragraphe |
| 1637 | 1637 | include_spip('inc/texte'); |
| 1638 | 1638 | $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad)); |
| 1639 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1639 | + $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1640 | 1640 | $trad = code_echappement($trad, 'multi', false, $mode); |
| 1641 | 1641 | $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
| 1642 | 1642 | if (lang_dir($l) !== lang_dir($lang)) { |
@@ -1829,7 +1829,7 @@ discard block |
||
| 1829 | 1829 | if (is_array($balise)) { |
| 1830 | 1830 | array_walk( |
| 1831 | 1831 | $balise, |
| 1832 | - function(&$a, $key, $t){ |
|
| 1832 | + function(&$a, $key, $t) { |
|
| 1833 | 1833 | $a = extraire_attribut($a, $t); |
| 1834 | 1834 | }, |
| 1835 | 1835 | $attribut |
@@ -1916,14 +1916,14 @@ discard block |
||
| 1916 | 1916 | |
| 1917 | 1917 | if ($old !== null) { |
| 1918 | 1918 | // Remplacer l'ancien attribut du meme nom |
| 1919 | - $balise = $r[1] . $insert . $r[5]; |
|
| 1919 | + $balise = $r[1].$insert.$r[5]; |
|
| 1920 | 1920 | } else { |
| 1921 | 1921 | // preferer une balise " />" (comme <img />) |
| 1922 | 1922 | if (preg_match(',/>,', $balise)) { |
| 1923 | - $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1); |
|
| 1923 | + $balise = preg_replace(",\s?/>,S", $insert." />", $balise, 1); |
|
| 1924 | 1924 | } // sinon une balise <a ...> ... </a> |
| 1925 | 1925 | else { |
| 1926 | - $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1); |
|
| 1926 | + $balise = preg_replace(",\s?>,S", $insert.">", $balise, 1); |
|
| 1927 | 1927 | } |
| 1928 | 1928 | } |
| 1929 | 1929 | |
@@ -1965,8 +1965,8 @@ discard block |
||
| 1965 | 1965 | // |
| 1966 | 1966 | // Quelques fonctions de calcul arithmetique |
| 1967 | 1967 | // |
| 1968 | -function floatstr($a) { return str_replace(',','.',(string)floatval($a)); } |
|
| 1969 | -function strize($f, $a, $b) { return floatstr($f(floatstr($a),floatstr($b))); } |
|
| 1968 | +function floatstr($a) { return str_replace(',', '.', (string) floatval($a)); } |
|
| 1969 | +function strize($f, $a, $b) { return floatstr($f(floatstr($a), floatstr($b))); } |
|
| 1970 | 1970 | |
| 1971 | 1971 | /** |
| 1972 | 1972 | * Additionne 2 nombres |
@@ -1986,7 +1986,7 @@ discard block |
||
| 1986 | 1986 | function plus($a, $b) { |
| 1987 | 1987 | return $a + $b; |
| 1988 | 1988 | } |
| 1989 | -function strplus($a, $b) {return strize('plus', $a, $b);} |
|
| 1989 | +function strplus($a, $b) {return strize('plus', $a, $b); } |
|
| 1990 | 1990 | /** |
| 1991 | 1991 | * Soustrait 2 nombres |
| 1992 | 1992 | * |
@@ -2005,7 +2005,7 @@ discard block |
||
| 2005 | 2005 | function moins($a, $b) { |
| 2006 | 2006 | return $a - $b; |
| 2007 | 2007 | } |
| 2008 | -function strmoins($a, $b) {return strize('moins', $a, $b);} |
|
| 2008 | +function strmoins($a, $b) {return strize('moins', $a, $b); } |
|
| 2009 | 2009 | |
| 2010 | 2010 | /** |
| 2011 | 2011 | * Multiplie 2 nombres |
@@ -2026,7 +2026,7 @@ discard block |
||
| 2026 | 2026 | function mult($a, $b) { |
| 2027 | 2027 | return $a * $b; |
| 2028 | 2028 | } |
| 2029 | -function strmult($a, $b) {return strize('mult', $a, $b);} |
|
| 2029 | +function strmult($a, $b) {return strize('mult', $a, $b); } |
|
| 2030 | 2030 | |
| 2031 | 2031 | /** |
| 2032 | 2032 | * Divise 2 nombres |
@@ -2047,7 +2047,7 @@ discard block |
||
| 2047 | 2047 | function div($a, $b) { |
| 2048 | 2048 | return $b ? $a / $b : 0; |
| 2049 | 2049 | } |
| 2050 | -function strdiv($a, $b) {return strize('div', $a, $b);} |
|
| 2050 | +function strdiv($a, $b) {return strize('div', $a, $b); } |
|
| 2051 | 2051 | |
| 2052 | 2052 | /** |
| 2053 | 2053 | * Retourne le modulo 2 nombres |
@@ -2088,13 +2088,13 @@ discard block |
||
| 2088 | 2088 | if (!defined('_TAGS_NOM_AUTEUR')) { |
| 2089 | 2089 | define('_TAGS_NOM_AUTEUR', ''); |
| 2090 | 2090 | } |
| 2091 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2091 | + $tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR)); |
|
| 2092 | 2092 | foreach ($tags_acceptes as $tag) { |
| 2093 | 2093 | if (strlen($tag)) { |
| 2094 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2095 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2096 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2097 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2094 | + $remp1[] = '<'.trim($tag).'>'; |
|
| 2095 | + $remp1[] = '</'.trim($tag).'>'; |
|
| 2096 | + $remp2[] = '\x60'.trim($tag).'\x61'; |
|
| 2097 | + $remp2[] = '\x60/'.trim($tag).'\x61'; |
|
| 2098 | 2098 | } |
| 2099 | 2099 | } |
| 2100 | 2100 | $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
@@ -2157,7 +2157,7 @@ discard block |
||
| 2157 | 2157 | $s[] = preg_replace(',>[^<]+</a>,S', |
| 2158 | 2158 | '>' |
| 2159 | 2159 | . http_img_pack('attachment-16.png', $t, |
| 2160 | - 'title="' . attribut_html($t) . '"') |
|
| 2160 | + 'title="'.attribut_html($t).'"') |
|
| 2161 | 2161 | . '</a>', $tag); |
| 2162 | 2162 | } |
| 2163 | 2163 | } |
@@ -2218,10 +2218,10 @@ discard block |
||
| 2218 | 2218 | $fichier = basename($url); |
| 2219 | 2219 | |
| 2220 | 2220 | return '<a rel="enclosure"' |
| 2221 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2222 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2223 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2224 | - . '>' . $fichier . '</a>'; |
|
| 2221 | + . ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2222 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2223 | + . ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '') |
|
| 2224 | + . '>'.$fichier.'</a>'; |
|
| 2225 | 2225 | } |
| 2226 | 2226 | |
| 2227 | 2227 | /** |
@@ -2249,9 +2249,9 @@ discard block |
||
| 2249 | 2249 | } # vieux data |
| 2250 | 2250 | $fichier = basename($url); |
| 2251 | 2251 | $enclosures[] = '<enclosure' |
| 2252 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2253 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2254 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2252 | + . ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2253 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2254 | + . ($length ? ' length="'.$length.'"' : '') |
|
| 2255 | 2255 | . ' />'; |
| 2256 | 2256 | } |
| 2257 | 2257 | } |
@@ -2277,7 +2277,7 @@ discard block |
||
| 2277 | 2277 | if (extraire_attribut($e, rel) == 'tag') { |
| 2278 | 2278 | $subjects .= '<dc:subject>' |
| 2279 | 2279 | . texte_backend(textebrut($e)) |
| 2280 | - . '</dc:subject>' . "\n"; |
|
| 2280 | + . '</dc:subject>'."\n"; |
|
| 2281 | 2281 | } |
| 2282 | 2282 | } |
| 2283 | 2283 | |
@@ -2313,7 +2313,7 @@ discard block |
||
| 2313 | 2313 | if (is_array($texte)) { |
| 2314 | 2314 | array_walk( |
| 2315 | 2315 | $texte, |
| 2316 | - function(&$a, $key, $t){ |
|
| 2316 | + function(&$a, $key, $t) { |
|
| 2317 | 2317 | $a = extraire_balise($a, $t); |
| 2318 | 2318 | }, |
| 2319 | 2319 | $tag |
@@ -2357,7 +2357,7 @@ discard block |
||
| 2357 | 2357 | if (is_array($texte)) { |
| 2358 | 2358 | array_walk( |
| 2359 | 2359 | $texte, |
| 2360 | - function(&$a, $key, $t){ |
|
| 2360 | + function(&$a, $key, $t) { |
|
| 2361 | 2361 | $a = extraire_balises($a, $t); |
| 2362 | 2362 | }, |
| 2363 | 2363 | $tag |
@@ -2483,7 +2483,7 @@ discard block |
||
| 2483 | 2483 | if ($fond != '404') { |
| 2484 | 2484 | $contexte = array_shift($p); |
| 2485 | 2485 | $contexte['page'] = $fond; |
| 2486 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2486 | + $action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2487 | 2487 | } |
| 2488 | 2488 | } |
| 2489 | 2489 | // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
@@ -2538,9 +2538,9 @@ discard block |
||
| 2538 | 2538 | . '"' |
| 2539 | 2539 | . (is_null($val) |
| 2540 | 2540 | ? '' |
| 2541 | - : ' value="' . entites_html($val) . '"' |
|
| 2541 | + : ' value="'.entites_html($val).'"' |
|
| 2542 | 2542 | ) |
| 2543 | - . ' type="hidden"' . "\n/>"; |
|
| 2543 | + . ' type="hidden"'."\n/>"; |
|
| 2544 | 2544 | } |
| 2545 | 2545 | |
| 2546 | 2546 | return join("", $hidden); |
@@ -2703,12 +2703,12 @@ discard block |
||
| 2703 | 2703 | if ($pas < 1) { |
| 2704 | 2704 | return ''; |
| 2705 | 2705 | } |
| 2706 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 2707 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 2706 | + $ancre = 'pagination'.$nom; // #pagination_articles |
|
| 2707 | + $debut = 'debut'.$nom; // 'debut_articles' |
|
| 2708 | 2708 | |
| 2709 | 2709 | // n'afficher l'ancre qu'une fois |
| 2710 | 2710 | if (!isset($ancres[$ancre])) { |
| 2711 | - $bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>"; |
|
| 2711 | + $bloc_ancre = $ancres[$ancre] = "<a name='".$ancre."' id='".$ancre."'></a>"; |
|
| 2712 | 2712 | } else { |
| 2713 | 2713 | $bloc_ancre = ''; |
| 2714 | 2714 | } |
@@ -2738,7 +2738,7 @@ discard block |
||
| 2738 | 2738 | } |
| 2739 | 2739 | |
| 2740 | 2740 | if ($modele) { |
| 2741 | - $modele = '_' . $modele; |
|
| 2741 | + $modele = '_'.$modele; |
|
| 2742 | 2742 | } |
| 2743 | 2743 | |
| 2744 | 2744 | return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect); |
@@ -2763,7 +2763,7 @@ discard block |
||
| 2763 | 2763 | return preg_replace_callback( |
| 2764 | 2764 | ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
| 2765 | 2765 | function($x) use ($path) { |
| 2766 | - return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2766 | + return "url('".suivre_lien($path, $x[1])."')"; |
|
| 2767 | 2767 | }, |
| 2768 | 2768 | $contenu |
| 2769 | 2769 | ); |
@@ -2825,14 +2825,14 @@ discard block |
||
| 2825 | 2825 | ) { |
| 2826 | 2826 | $distant = true; |
| 2827 | 2827 | $cssf = parse_url($css); |
| 2828 | - $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : ""); |
|
| 2828 | + $cssf = $cssf['path'].($cssf['query'] ? "?".$cssf['query'] : ""); |
|
| 2829 | 2829 | $cssf = preg_replace(',[?:&=],', "_", $cssf); |
| 2830 | 2830 | } else { |
| 2831 | 2831 | $distant = false; |
| 2832 | 2832 | $cssf = $css; |
| 2833 | 2833 | // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
| 2834 | 2834 | //propose (rien a faire dans ce cas) |
| 2835 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2835 | + $f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css); |
|
| 2836 | 2836 | if (@file_exists($f)) { |
| 2837 | 2837 | return $f; |
| 2838 | 2838 | } |
@@ -2842,7 +2842,7 @@ discard block |
||
| 2842 | 2842 | $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
| 2843 | 2843 | $f = $dir_var |
| 2844 | 2844 | . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
| 2845 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2845 | + . '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css'; |
|
| 2846 | 2846 | |
| 2847 | 2847 | // la css peut etre distante (url absolue !) |
| 2848 | 2848 | if ($distant) { |
@@ -2881,8 +2881,8 @@ discard block |
||
| 2881 | 2881 | } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
| 2882 | 2882 | elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
| 2883 | 2883 | $css_direction = substr($css_direction, strlen($dir_var)); |
| 2884 | - $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction; |
|
| 2885 | - $css_direction = "/@@@@@@/" . $css_direction; |
|
| 2884 | + $src_faux_abs["/@@@@@@/".$css_direction] = $css_direction; |
|
| 2885 | + $css_direction = "/@@@@@@/".$css_direction; |
|
| 2886 | 2886 | } |
| 2887 | 2887 | $src[] = $regs[0][$k]; |
| 2888 | 2888 | $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
@@ -2931,7 +2931,7 @@ discard block |
||
| 2931 | 2931 | |
| 2932 | 2932 | $f = basename($css, '.css'); |
| 2933 | 2933 | $f = sous_repertoire(_DIR_VAR, 'cache-css') |
| 2934 | - . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 2934 | + . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f) |
|
| 2935 | 2935 | . '.css'; |
| 2936 | 2936 | |
| 2937 | 2937 | if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
@@ -2940,7 +2940,7 @@ discard block |
||
| 2940 | 2940 | |
| 2941 | 2941 | if ($url_absolue_css == $css) { |
| 2942 | 2942 | if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
| 2943 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 2943 | + or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu) |
|
| 2944 | 2944 | ) { |
| 2945 | 2945 | include_spip('inc/distant'); |
| 2946 | 2946 | if (!$contenu = recuperer_page($css)) { |
@@ -3050,7 +3050,7 @@ discard block |
||
| 3050 | 3050 | $expression = str_replace("\/", "/", $expression); |
| 3051 | 3051 | $expression = str_replace("/", "\/", $expression); |
| 3052 | 3052 | |
| 3053 | - if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3053 | + if (preg_match('/'.$expression.'/'.$modif, $texte, $r)) { |
|
| 3054 | 3054 | if (isset($r[$capte])) { |
| 3055 | 3055 | return $r[$capte]; |
| 3056 | 3056 | } else { |
@@ -3088,7 +3088,7 @@ discard block |
||
| 3088 | 3088 | $expression = str_replace("\/", "/", $expression); |
| 3089 | 3089 | $expression = str_replace("/", "\/", $expression); |
| 3090 | 3090 | |
| 3091 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3091 | + return preg_replace('/'.$expression.'/'.$modif, $replace, $texte); |
|
| 3092 | 3092 | } |
| 3093 | 3093 | |
| 3094 | 3094 | |
@@ -3107,7 +3107,7 @@ discard block |
||
| 3107 | 3107 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3108 | 3108 | |
| 3109 | 3109 | // Verifier dans le texte & les notes (pas beau, helas) |
| 3110 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3110 | + $t = $letexte.$GLOBALS['les_notes']; |
|
| 3111 | 3111 | |
| 3112 | 3112 | if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
| 3113 | 3113 | and preg_match_all( |
@@ -3117,7 +3117,7 @@ discard block |
||
| 3117 | 3117 | if (!isset($doublons['documents'])) { |
| 3118 | 3118 | $doublons['documents'] = ""; |
| 3119 | 3119 | } |
| 3120 | - $doublons['documents'] .= "," . join(',', $matches[1]); |
|
| 3120 | + $doublons['documents'] .= ",".join(',', $matches[1]); |
|
| 3121 | 3121 | } |
| 3122 | 3122 | |
| 3123 | 3123 | return $letexte; |
@@ -3174,7 +3174,7 @@ discard block |
||
| 3174 | 3174 | if ($env) { |
| 3175 | 3175 | foreach ($env as $i => $j) { |
| 3176 | 3176 | if (is_string($j) and !in_array($i, $ignore_params)) { |
| 3177 | - $texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />"; |
|
| 3177 | + $texte .= "<param name='".$i."'\n\tvalue='".$j."' />"; |
|
| 3178 | 3178 | } |
| 3179 | 3179 | } |
| 3180 | 3180 | } |
@@ -3213,7 +3213,7 @@ discard block |
||
| 3213 | 3213 | if ($env) { |
| 3214 | 3214 | foreach ($env as $i => $j) { |
| 3215 | 3215 | if (is_string($j) and !in_array($i, $ignore_params)) { |
| 3216 | - $texte .= $i . "='" . $j . "' "; |
|
| 3216 | + $texte .= $i."='".$j."' "; |
|
| 3217 | 3217 | } |
| 3218 | 3218 | } |
| 3219 | 3219 | } |
@@ -3309,12 +3309,12 @@ discard block |
||
| 3309 | 3309 | return ""; |
| 3310 | 3310 | } |
| 3311 | 3311 | } |
| 3312 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3312 | + $atts .= " width='".$largeur."' height='".$hauteur."'"; |
|
| 3313 | 3313 | } |
| 3314 | 3314 | |
| 3315 | - return "<img src='$img' alt='" . attribut_html($alt ? $alt : $title) . "'" |
|
| 3316 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3317 | - . " " . ltrim($atts) |
|
| 3315 | + return "<img src='$img' alt='".attribut_html($alt ? $alt : $title)."'" |
|
| 3316 | + . ($title ? ' title="'.attribut_html($title).'"' : '') |
|
| 3317 | + . " ".ltrim($atts) |
|
| 3318 | 3318 | . " />"; |
| 3319 | 3319 | } |
| 3320 | 3320 | |
@@ -3326,7 +3326,7 @@ discard block |
||
| 3326 | 3326 | * @return string |
| 3327 | 3327 | */ |
| 3328 | 3328 | function http_style_background($img, $att = '') { |
| 3329 | - return " style='background" . ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";'"; |
|
| 3329 | + return " style='background".($att ? "" : "-image").": url(\"".chemin_image($img)."\")".($att ? (' '.$att) : '').";'"; |
|
| 3330 | 3330 | } |
| 3331 | 3331 | |
| 3332 | 3332 | /** |
@@ -3341,7 +3341,7 @@ discard block |
||
| 3341 | 3341 | * Code HTML de la balise IMG |
| 3342 | 3342 | */ |
| 3343 | 3343 | function filtre_balise_img_dist($img, $alt = "", $class = "") { |
| 3344 | - return http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '', |
|
| 3344 | + return http_img_pack($img, $alt, $class ? " class='".attribut_html($class)."'" : '', '', |
|
| 3345 | 3345 | array('chemin_image' => false, 'utiliser_suffixe_size' => false)); |
| 3346 | 3346 | } |
| 3347 | 3347 | |
@@ -3367,7 +3367,7 @@ discard block |
||
| 3367 | 3367 | $texte = ''; |
| 3368 | 3368 | if (is_array($tableau)) { |
| 3369 | 3369 | foreach ($tableau as $k => $v) { |
| 3370 | - $res = recuperer_fond('modeles/' . $modele, |
|
| 3370 | + $res = recuperer_fond('modeles/'.$modele, |
|
| 3371 | 3371 | array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v))) |
| 3372 | 3372 | ); |
| 3373 | 3373 | $texte .= $res; |
@@ -3544,7 +3544,7 @@ discard block |
||
| 3544 | 3544 | } |
| 3545 | 3545 | |
| 3546 | 3546 | $c = serialize($c); |
| 3547 | - $cle = calculer_cle_action($form . $c); |
|
| 3547 | + $cle = calculer_cle_action($form.$c); |
|
| 3548 | 3548 | $c = "$cle:$c"; |
| 3549 | 3549 | |
| 3550 | 3550 | // on ne stocke pas les contextes dans des fichiers caches |
@@ -3594,15 +3594,15 @@ discard block |
||
| 3594 | 3594 | } |
| 3595 | 3595 | // toujours encoder l'url source dans le bloc ajax |
| 3596 | 3596 | $r = self(); |
| 3597 | - $r = ' data-origin="' . $r . '"'; |
|
| 3597 | + $r = ' data-origin="'.$r.'"'; |
|
| 3598 | 3598 | $class = 'ajaxbloc'; |
| 3599 | 3599 | if ($ajaxid and is_string($ajaxid)) { |
| 3600 | 3600 | // ajaxid est normalement conforme a un nom de classe css |
| 3601 | 3601 | // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
| 3602 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3602 | + $class .= ' ajax-id-'.entites_html($ajaxid); |
|
| 3603 | 3603 | } |
| 3604 | 3604 | |
| 3605 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3605 | + return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3606 | 3606 | } |
| 3607 | 3607 | |
| 3608 | 3608 | /** |
@@ -3641,11 +3641,11 @@ discard block |
||
| 3641 | 3641 | // extraire la signature en debut de contexte |
| 3642 | 3642 | // et la verifier avant de deserializer |
| 3643 | 3643 | // format : signature:donneesserializees |
| 3644 | - if ($p = strpos($c,":")){ |
|
| 3645 | - $cle = substr($c,0,$p); |
|
| 3646 | - $c = substr($c,$p+1); |
|
| 3644 | + if ($p = strpos($c, ":")) { |
|
| 3645 | + $cle = substr($c, 0, $p); |
|
| 3646 | + $c = substr($c, $p + 1); |
|
| 3647 | 3647 | |
| 3648 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 3648 | + if ($cle == calculer_cle_action($form.$c)) { |
|
| 3649 | 3649 | $env = @unserialize($c); |
| 3650 | 3650 | return $env; |
| 3651 | 3651 | } |
@@ -3746,9 +3746,9 @@ discard block |
||
| 3746 | 3746 | } else { |
| 3747 | 3747 | $bal = 'a'; |
| 3748 | 3748 | $att = "href='$url'" |
| 3749 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 3750 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 3751 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 3749 | + . ($title ? " title='".attribut_html($title)."'" : '') |
|
| 3750 | + . ($class ? " class='".attribut_html($class)."'" : '') |
|
| 3751 | + . ($rel ? " rel='".attribut_html($rel)."'" : '') |
|
| 3752 | 3752 | . $evt; |
| 3753 | 3753 | } |
| 3754 | 3754 | if ($libelle === null) { |
@@ -3822,7 +3822,7 @@ discard block |
||
| 3822 | 3822 | } |
| 3823 | 3823 | |
| 3824 | 3824 | // ajouter le type d'objet dans la class de l'icone |
| 3825 | - $class .= " " . substr(basename($fond), 0, -4); |
|
| 3825 | + $class .= " ".substr(basename($fond), 0, -4); |
|
| 3826 | 3826 | |
| 3827 | 3827 | $alt = attribut_html($texte); |
| 3828 | 3828 | $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
@@ -3847,7 +3847,7 @@ discard block |
||
| 3847 | 3847 | if ($fonction) { |
| 3848 | 3848 | // 2 images pour composer l'icone : le fond (article) en background, |
| 3849 | 3849 | // la fonction (new) en image |
| 3850 | - $icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n" . |
|
| 3850 | + $icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n". |
|
| 3851 | 3851 | http_style_background($fond)); |
| 3852 | 3852 | } else { |
| 3853 | 3853 | $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
@@ -4081,13 +4081,13 @@ discard block |
||
| 4081 | 4081 | $res = ""; |
| 4082 | 4082 | foreach ($boutons as $page => $detail) { |
| 4083 | 4083 | if ($detail->icone and strlen(trim($detail->icone))) { |
| 4084 | - $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}"; |
|
| 4084 | + $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(".$detail->icone.");}"; |
|
| 4085 | 4085 | } |
| 4086 | 4086 | $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones "); |
| 4087 | 4087 | if (is_array($detail->sousmenu)) { |
| 4088 | 4088 | foreach ($detail->sousmenu as $souspage => $sousdetail) { |
| 4089 | 4089 | if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
| 4090 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}"; |
|
| 4090 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url(".$sousdetail->icone.");}"; |
|
| 4091 | 4091 | } |
| 4092 | 4092 | } |
| 4093 | 4093 | } |
@@ -4113,17 +4113,17 @@ discard block |
||
| 4113 | 4113 | */ |
| 4114 | 4114 | function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") { |
| 4115 | 4115 | if ($confirm) { |
| 4116 | - $confirm = "confirm(\"" . attribut_html($confirm) . "\")"; |
|
| 4116 | + $confirm = "confirm(\"".attribut_html($confirm)."\")"; |
|
| 4117 | 4117 | if ($callback) { |
| 4118 | 4118 | $callback = "$confirm?($callback):false"; |
| 4119 | 4119 | } else { |
| 4120 | 4120 | $callback = $confirm; |
| 4121 | 4121 | } |
| 4122 | 4122 | } |
| 4123 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ""; |
|
| 4123 | + $onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : ""; |
|
| 4124 | 4124 | $title = $title ? " title='$title'" : ""; |
| 4125 | 4125 | |
| 4126 | - return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4126 | + return "<form class='bouton_action_post $class' method='post' action='$url'><div>".form_hidden($url) |
|
| 4127 | 4127 | . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>"; |
| 4128 | 4128 | } |
| 4129 | 4129 | |
@@ -4262,14 +4262,14 @@ discard block |
||
| 4262 | 4262 | $champ_titre = ""; |
| 4263 | 4263 | if ($demande_titre) { |
| 4264 | 4264 | // si pas de titre declare mais champ titre, il sera peuple par le select * |
| 4265 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4265 | + $champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : ''; |
|
| 4266 | 4266 | } |
| 4267 | 4267 | include_spip('base/abstract_sql'); |
| 4268 | 4268 | include_spip('base/connect_sql'); |
| 4269 | 4269 | $objets[$type_objet][$id_objet] = sql_fetsel( |
| 4270 | - '*' . $champ_titre, |
|
| 4270 | + '*'.$champ_titre, |
|
| 4271 | 4271 | $desc['table_sql'], |
| 4272 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4272 | + id_table_objet($type_objet).' = '.intval($id_objet) |
|
| 4273 | 4273 | ); |
| 4274 | 4274 | } |
| 4275 | 4275 | |
@@ -4339,7 +4339,7 @@ discard block |
||
| 4339 | 4339 | return $texte; |
| 4340 | 4340 | } |
| 4341 | 4341 | |
| 4342 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4342 | + $traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement); |
|
| 4343 | 4343 | |
| 4344 | 4344 | // Fournir $connect et $Pile[0] au traitement si besoin |
| 4345 | 4345 | $Pile = array(0 => $env); |
@@ -4373,7 +4373,7 @@ discard block |
||
| 4373 | 4373 | } |
| 4374 | 4374 | $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
| 4375 | 4375 | |
| 4376 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>"; |
|
| 4376 | + return "<a href='$url' class='$objet'>".couper($titre, $longueur)."</a>"; |
|
| 4377 | 4377 | } |
| 4378 | 4378 | |
| 4379 | 4379 | |
@@ -4392,10 +4392,10 @@ discard block |
||
| 4392 | 4392 | function wrap($texte, $wrap) { |
| 4393 | 4393 | $balises = extraire_balises($wrap); |
| 4394 | 4394 | if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
| 4395 | - $texte = $wrap . $texte; |
|
| 4395 | + $texte = $wrap.$texte; |
|
| 4396 | 4396 | $regs = array_reverse($regs[1]); |
| 4397 | - $wrap = "</" . implode("></", $regs) . ">"; |
|
| 4398 | - $texte = $texte . $wrap; |
|
| 4397 | + $wrap = "</".implode("></", $regs).">"; |
|
| 4398 | + $texte = $texte.$wrap; |
|
| 4399 | 4399 | } |
| 4400 | 4400 | |
| 4401 | 4401 | return $texte; |
@@ -4426,7 +4426,7 @@ discard block |
||
| 4426 | 4426 | |
| 4427 | 4427 | // caster $u en array si besoin |
| 4428 | 4428 | if (is_object($u)) { |
| 4429 | - $u = (array)$u; |
|
| 4429 | + $u = (array) $u; |
|
| 4430 | 4430 | } |
| 4431 | 4431 | |
| 4432 | 4432 | if (is_array($u)) { |
@@ -4447,7 +4447,7 @@ discard block |
||
| 4447 | 4447 | // sinon on passe a la ligne et on indente |
| 4448 | 4448 | $i_str = str_pad("", $indent, " "); |
| 4449 | 4449 | foreach ($u as $k => $v) { |
| 4450 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4450 | + $out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2); |
|
| 4451 | 4451 | } |
| 4452 | 4452 | |
| 4453 | 4453 | return $out; |
@@ -4500,7 +4500,7 @@ discard block |
||
| 4500 | 4500 | * @return string |
| 4501 | 4501 | */ |
| 4502 | 4502 | function objet_icone($objet, $taille = 24) { |
| 4503 | - $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png"; |
|
| 4503 | + $icone = objet_info($objet, 'icone_objet')."-".$taille.".png"; |
|
| 4504 | 4504 | $icone = chemin_image($icone); |
| 4505 | 4505 | $balise_img = charger_filtre('balise_img'); |
| 4506 | 4506 | |
@@ -4524,12 +4524,12 @@ discard block |
||
| 4524 | 4524 | * @param array $options |
| 4525 | 4525 | * @return string |
| 4526 | 4526 | */ |
| 4527 | -function objet_T($objet, $chaine, $args = array(), $options = array()){ |
|
| 4528 | - $chaine = explode(':',$chaine); |
|
| 4529 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) { |
|
| 4527 | +function objet_T($objet, $chaine, $args = array(), $options = array()) { |
|
| 4528 | + $chaine = explode(':', $chaine); |
|
| 4529 | + if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, array('force'=>false)))) { |
|
| 4530 | 4530 | return $t; |
| 4531 | 4531 | } |
| 4532 | - $chaine = implode(':',$chaine); |
|
| 4532 | + $chaine = implode(':', $chaine); |
|
| 4533 | 4533 | return _T($chaine, $args, $options); |
| 4534 | 4534 | } |
| 4535 | 4535 | |
@@ -4589,11 +4589,11 @@ discard block |
||
| 4589 | 4589 | $cache = recuperer_fond($fond, $contexte, $options, $connect); |
| 4590 | 4590 | |
| 4591 | 4591 | // calculer le nom de la css |
| 4592 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 4592 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension); |
|
| 4593 | 4593 | $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond)); |
| 4594 | 4594 | $contexte_implicite = calculer_contexte_implicite(); |
| 4595 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" |
|
| 4596 | - . substr(md5($fond . serialize($contexte_implicite) . serialize($contexte) . $connect), 0, 8) |
|
| 4595 | + $filename = $dir_var.$extension."dyn-$nom_safe-" |
|
| 4596 | + . substr(md5($fond.serialize($contexte_implicite).serialize($contexte).$connect), 0, 8) |
|
| 4597 | 4597 | . ".$extension"; |
| 4598 | 4598 | |
| 4599 | 4599 | // mettre a jour le fichier si il n'existe pas |
@@ -4601,8 +4601,8 @@ discard block |
||
| 4601 | 4601 | // le dernier fichier produit est toujours suffixe par .last |
| 4602 | 4602 | // et recopie sur le fichier cible uniquement si il change |
| 4603 | 4603 | if (!file_exists($filename) |
| 4604 | - or !file_exists($filename . ".last") |
|
| 4605 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified']) |
|
| 4604 | + or !file_exists($filename.".last") |
|
| 4605 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.".last") < $cache['lastmodified']) |
|
| 4606 | 4606 | or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
| 4607 | 4607 | ) { |
| 4608 | 4608 | $contenu = $cache['texte']; |
@@ -4621,15 +4621,15 @@ discard block |
||
| 4621 | 4621 | } |
| 4622 | 4622 | // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
| 4623 | 4623 | // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
| 4624 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 4624 | + $comment .= "}\n md5:".md5($contenu)." */\n"; |
|
| 4625 | 4625 | } |
| 4626 | 4626 | // et ecrire le fichier |
| 4627 | - ecrire_fichier($filename . ".last", $comment . $contenu); |
|
| 4627 | + ecrire_fichier($filename.".last", $comment.$contenu); |
|
| 4628 | 4628 | // regarder si on recopie |
| 4629 | 4629 | if (!file_exists($filename) |
| 4630 | - or md5_file($filename) !== md5_file($filename . ".last") |
|
| 4630 | + or md5_file($filename) !== md5_file($filename.".last") |
|
| 4631 | 4631 | ) { |
| 4632 | - @copy($filename . ".last", $filename); |
|
| 4632 | + @copy($filename.".last", $filename); |
|
| 4633 | 4633 | clearstatcache(true, $filename); // eviter que PHP ne reserve le vieux timestamp |
| 4634 | 4634 | } |
| 4635 | 4635 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @return string Fonction PHP correspondante du filtre |
| 43 | 43 | */ |
| 44 | 44 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 45 | - include_spip('public/parametrer'); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_spip('public/parametrer'); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -75,36 +75,36 @@ discard block |
||
| 75 | 75 | * Fonction PHP correspondante du filtre demandé |
| 76 | 76 | */ |
| 77 | 77 | function chercher_filtre($fonc, $default = null) { |
| 78 | - if (!$fonc) { |
|
| 79 | - return $default; |
|
| 80 | - } |
|
| 81 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 82 | - // Foo::Bar |
|
| 83 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 84 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 85 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 86 | - $f = chercher_filtre($nom); |
|
| 87 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 88 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 89 | - if (!$f and $nom !== $fonc) { |
|
| 90 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return $f; |
|
| 94 | - } |
|
| 95 | - foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) { |
|
| 96 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 97 | - // fonction ou name\space\fonction |
|
| 98 | - if (is_callable($f)) { |
|
| 99 | - return $f; |
|
| 100 | - } |
|
| 101 | - // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 102 | - elseif (false === strpos($f, '::') and is_callable(array($f))) { |
|
| 103 | - return $f; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $default; |
|
| 78 | + if (!$fonc) { |
|
| 79 | + return $default; |
|
| 80 | + } |
|
| 81 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 82 | + // Foo::Bar |
|
| 83 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 84 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 85 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 86 | + $f = chercher_filtre($nom); |
|
| 87 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 88 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 89 | + if (!$f and $nom !== $fonc) { |
|
| 90 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return $f; |
|
| 94 | + } |
|
| 95 | + foreach (array('filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc) as $f) { |
|
| 96 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 97 | + // fonction ou name\space\fonction |
|
| 98 | + if (is_callable($f)) { |
|
| 99 | + return $f; |
|
| 100 | + } |
|
| 101 | + // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 102 | + elseif (false === strpos($f, '::') and is_callable(array($f))) { |
|
| 103 | + return $f; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $default; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -128,20 +128,20 @@ discard block |
||
| 128 | 128 | * Chaîne vide sinon (filtre introuvable). |
| 129 | 129 | **/ |
| 130 | 130 | function appliquer_filtre($arg, $filtre, $force = null) { |
| 131 | - $f = chercher_filtre($filtre); |
|
| 132 | - if (!$f) { |
|
| 133 | - if (!$force) { |
|
| 134 | - return ''; |
|
| 135 | - } else { |
|
| 136 | - return $arg; |
|
| 137 | - } |
|
| 138 | - } |
|
| 131 | + $f = chercher_filtre($filtre); |
|
| 132 | + if (!$f) { |
|
| 133 | + if (!$force) { |
|
| 134 | + return ''; |
|
| 135 | + } else { |
|
| 136 | + return $arg; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - $args = func_get_args(); |
|
| 141 | - array_shift($args); // enlever $arg |
|
| 142 | - array_shift($args); // enlever $filtre |
|
| 143 | - array_unshift($args, $arg); // remettre $arg |
|
| 144 | - return call_user_func_array($f, $args); |
|
| 140 | + $args = func_get_args(); |
|
| 141 | + array_shift($args); // enlever $arg |
|
| 142 | + array_shift($args); // enlever $filtre |
|
| 143 | + array_unshift($args, $arg); // remettre $arg |
|
| 144 | + return call_user_func_array($f, $args); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -157,12 +157,12 @@ discard block |
||
| 157 | 157 | * Version de SPIP |
| 158 | 158 | **/ |
| 159 | 159 | function spip_version() { |
| 160 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 161 | - if ($svn_revision = version_svn_courante(_DIR_RACINE)) { |
|
| 162 | - $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 163 | - } |
|
| 160 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 161 | + if ($svn_revision = version_svn_courante(_DIR_RACINE)) { |
|
| 162 | + $version .= ($svn_revision < 0 ? ' SVN' : '') . ' [' . abs($svn_revision) . ']'; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - return $version; |
|
| 165 | + return $version; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | |
@@ -181,43 +181,43 @@ discard block |
||
| 181 | 181 | * |
| 182 | 182 | **/ |
| 183 | 183 | function version_svn_courante($dir) { |
| 184 | - if (!$dir) { |
|
| 185 | - $dir = '.'; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // version installee par paquet ZIP |
|
| 189 | - if (lire_fichier($dir . '/svn.revision', $c) |
|
| 190 | - and preg_match(',Revision: (\d+),', $c, $d) |
|
| 191 | - ) { |
|
| 192 | - return intval($d[1]); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - // version installee par SVN |
|
| 196 | - if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 197 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 198 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 199 | - if ($result) { |
|
| 200 | - $row = $result->fetchArray(); |
|
| 201 | - if ($row['changed_revision'] != "") { |
|
| 202 | - return -$row['changed_revision']; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } else if (lire_fichier($dir . '/.svn/entries', $c) |
|
| 206 | - and ( |
|
| 207 | - (preg_match_all( |
|
| 208 | - ',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER) |
|
| 209 | - and $v = max($r1[1]) |
|
| 210 | - ) |
|
| 211 | - or |
|
| 212 | - (preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4 |
|
| 213 | - and $v = $r1[1] |
|
| 214 | - )) |
|
| 215 | - ) { |
|
| 216 | - return -$v; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // Bug ou paquet fait main |
|
| 220 | - return 0; |
|
| 184 | + if (!$dir) { |
|
| 185 | + $dir = '.'; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // version installee par paquet ZIP |
|
| 189 | + if (lire_fichier($dir . '/svn.revision', $c) |
|
| 190 | + and preg_match(',Revision: (\d+),', $c, $d) |
|
| 191 | + ) { |
|
| 192 | + return intval($d[1]); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + // version installee par SVN |
|
| 196 | + if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 197 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 198 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 199 | + if ($result) { |
|
| 200 | + $row = $result->fetchArray(); |
|
| 201 | + if ($row['changed_revision'] != "") { |
|
| 202 | + return -$row['changed_revision']; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } else if (lire_fichier($dir . '/.svn/entries', $c) |
|
| 206 | + and ( |
|
| 207 | + (preg_match_all( |
|
| 208 | + ',committed-rev="([0-9]+)",', $c, $r1, PREG_PATTERN_ORDER) |
|
| 209 | + and $v = max($r1[1]) |
|
| 210 | + ) |
|
| 211 | + or |
|
| 212 | + (preg_match(',^\d.*dir[\r\n]+(\d+),ms', $c, $r1) # svn >= 1.4 |
|
| 213 | + and $v = $r1[1] |
|
| 214 | + )) |
|
| 215 | + ) { |
|
| 216 | + return -$v; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // Bug ou paquet fait main |
|
| 220 | + return 0; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -261,18 +261,18 @@ discard block |
||
| 261 | 261 | * Code HTML retourné par le filtre |
| 262 | 262 | **/ |
| 263 | 263 | function filtrer($filtre) { |
| 264 | - $tous = func_get_args(); |
|
| 265 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 266 | - return image_filtrer($tous); |
|
| 267 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 268 | - array_shift($tous); |
|
| 269 | - return call_user_func_array($f, $tous); |
|
| 270 | - } else { |
|
| 271 | - // le filtre n'existe pas, on provoque une erreur |
|
| 272 | - $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre))); |
|
| 273 | - erreur_squelette($msg); |
|
| 274 | - return ''; |
|
| 275 | - } |
|
| 264 | + $tous = func_get_args(); |
|
| 265 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 266 | + return image_filtrer($tous); |
|
| 267 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 268 | + array_shift($tous); |
|
| 269 | + return call_user_func_array($f, $tous); |
|
| 270 | + } else { |
|
| 271 | + // le filtre n'existe pas, on provoque une erreur |
|
| 272 | + $msg = array('zbug_erreur_filtre', array('filtre' => texte_script($filtre))); |
|
| 273 | + erreur_squelette($msg); |
|
| 274 | + return ''; |
|
| 275 | + } |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -289,11 +289,11 @@ discard block |
||
| 289 | 289 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 290 | 290 | */ |
| 291 | 291 | function trouver_filtre_matrice($filtre) { |
| 292 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 293 | - find_in_path($f, '', true); |
|
| 294 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 295 | - } |
|
| 296 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 292 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 293 | + find_in_path($f, '', true); |
|
| 294 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 295 | + } |
|
| 296 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
@@ -321,8 +321,8 @@ discard block |
||
| 321 | 321 | * @return mixed |
| 322 | 322 | */ |
| 323 | 323 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 324 | - $Pile['vars'][$key] = $val; |
|
| 325 | - return $continue ? $val : ''; |
|
| 324 | + $Pile['vars'][$key] = $val; |
|
| 325 | + return $continue ? $val : ''; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 349 | 349 | */ |
| 350 | 350 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 351 | - $Pile[0][$key] = $val; |
|
| 352 | - return $continue ? $val : ''; |
|
| 351 | + $Pile[0][$key] = $val; |
|
| 352 | + return $continue ? $val : ''; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -371,18 +371,18 @@ discard block |
||
| 371 | 371 | * @return mixed Retourne la valeur (sans la modifier). |
| 372 | 372 | */ |
| 373 | 373 | function filtre_debug($val, $key = null) { |
| 374 | - $debug = ( |
|
| 375 | - is_null($key) ? '' : (var_export($key, true) . " = ") |
|
| 376 | - ) . var_export($val, true); |
|
| 374 | + $debug = ( |
|
| 375 | + is_null($key) ? '' : (var_export($key, true) . " = ") |
|
| 376 | + ) . var_export($val, true); |
|
| 377 | 377 | |
| 378 | - include_spip('inc/autoriser'); |
|
| 379 | - if (autoriser('webmestre')) { |
|
| 380 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 381 | - } |
|
| 378 | + include_spip('inc/autoriser'); |
|
| 379 | + if (autoriser('webmestre')) { |
|
| 380 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | - spip_log($debug, 'debug'); |
|
| 383 | + spip_log($debug, 'debug'); |
|
| 384 | 384 | |
| 385 | - return $val; |
|
| 385 | + return $val; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | |
@@ -410,71 +410,71 @@ discard block |
||
| 410 | 410 | * Texte qui a reçu les filtres |
| 411 | 411 | **/ |
| 412 | 412 | function image_filtrer($args) { |
| 413 | - $filtre = array_shift($args); # enlever $filtre |
|
| 414 | - $texte = array_shift($args); |
|
| 415 | - if (!strlen($texte)) { |
|
| 416 | - return; |
|
| 417 | - } |
|
| 418 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 419 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 420 | - // Cas du nom de fichier local |
|
| 421 | - if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false |
|
| 422 | - and !preg_match(',^/|[<>]|\s,S', $texte) |
|
| 423 | - and ( |
|
| 424 | - file_exists(preg_replace(',[?].*$,', '', $texte)) |
|
| 425 | - or tester_url_absolue($texte) |
|
| 426 | - ) |
|
| 427 | - ) { |
|
| 428 | - array_unshift($args, "<img src='$texte' />"); |
|
| 429 | - $res = call_user_func_array($filtre, $args); |
|
| 430 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 431 | - return $res; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 435 | - if (preg_match_all( |
|
| 436 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 437 | - $texte, $tags, PREG_SET_ORDER)) { |
|
| 438 | - foreach ($tags as $tag) { |
|
| 439 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 440 | - if (!$class or |
|
| 441 | - (strpos($class, 'filtre_inactif') == false |
|
| 442 | - // compat historique a virer en 3.2 |
|
| 443 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 444 | - ) { |
|
| 445 | - array_unshift($args, $tag[3]); |
|
| 446 | - if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 447 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 448 | - if ($tag[1]) { |
|
| 449 | - $w = extraire_attribut($reduit, 'width'); |
|
| 450 | - if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) { |
|
| 451 | - $w = $regs[1]; |
|
| 452 | - } |
|
| 453 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 454 | - $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style); |
|
| 455 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 456 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - // traiter aussi un eventuel mouseover |
|
| 460 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 461 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 462 | - $srcover = $match[1]; |
|
| 463 | - array_shift($args); |
|
| 464 | - array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 465 | - $srcover_filter = call_user_func_array($filtre, $args); |
|
| 466 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 467 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 471 | - } |
|
| 472 | - array_shift($args); |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 477 | - return $texte; |
|
| 413 | + $filtre = array_shift($args); # enlever $filtre |
|
| 414 | + $texte = array_shift($args); |
|
| 415 | + if (!strlen($texte)) { |
|
| 416 | + return; |
|
| 417 | + } |
|
| 418 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 419 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 420 | + // Cas du nom de fichier local |
|
| 421 | + if (strpos(substr($texte, strlen(_DIR_RACINE)), '..') === false |
|
| 422 | + and !preg_match(',^/|[<>]|\s,S', $texte) |
|
| 423 | + and ( |
|
| 424 | + file_exists(preg_replace(',[?].*$,', '', $texte)) |
|
| 425 | + or tester_url_absolue($texte) |
|
| 426 | + ) |
|
| 427 | + ) { |
|
| 428 | + array_unshift($args, "<img src='$texte' />"); |
|
| 429 | + $res = call_user_func_array($filtre, $args); |
|
| 430 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 431 | + return $res; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 435 | + if (preg_match_all( |
|
| 436 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 437 | + $texte, $tags, PREG_SET_ORDER)) { |
|
| 438 | + foreach ($tags as $tag) { |
|
| 439 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 440 | + if (!$class or |
|
| 441 | + (strpos($class, 'filtre_inactif') == false |
|
| 442 | + // compat historique a virer en 3.2 |
|
| 443 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 444 | + ) { |
|
| 445 | + array_unshift($args, $tag[3]); |
|
| 446 | + if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 447 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 448 | + if ($tag[1]) { |
|
| 449 | + $w = extraire_attribut($reduit, 'width'); |
|
| 450 | + if (!$w and preg_match(",width:\s*(\d+)px,S", extraire_attribut($reduit, 'style'), $regs)) { |
|
| 451 | + $w = $regs[1]; |
|
| 452 | + } |
|
| 453 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 454 | + $style = preg_replace(",width:\s*\d+px,S", "width:${w}px", $style); |
|
| 455 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 456 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + // traiter aussi un eventuel mouseover |
|
| 460 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 461 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 462 | + $srcover = $match[1]; |
|
| 463 | + array_shift($args); |
|
| 464 | + array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 465 | + $srcover_filter = call_user_func_array($filtre, $args); |
|
| 466 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 467 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 471 | + } |
|
| 472 | + array_shift($args); |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 477 | + return $texte; |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | |
@@ -490,64 +490,64 @@ discard block |
||
| 490 | 490 | **/ |
| 491 | 491 | function taille_image($img) { |
| 492 | 492 | |
| 493 | - static $largeur_img = array(), $hauteur_img = array(); |
|
| 494 | - $srcWidth = 0; |
|
| 495 | - $srcHeight = 0; |
|
| 496 | - |
|
| 497 | - $logo = extraire_attribut($img, 'src'); |
|
| 498 | - |
|
| 499 | - if (!$logo) { |
|
| 500 | - $logo = $img; |
|
| 501 | - } else { |
|
| 502 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 503 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 507 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 508 | - if (tester_url_absolue($logo)) { |
|
| 509 | - include_spip('inc/distant'); |
|
| 510 | - $fichier = copie_locale($logo); |
|
| 511 | - $logo = $fichier ? _DIR_RACINE . $fichier : $logo; |
|
| 512 | - } |
|
| 513 | - if (($p = strpos($logo, '?')) !== false) { |
|
| 514 | - $logo = substr($logo, 0, $p); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - $srcsize = false; |
|
| 518 | - if (isset($largeur_img[$logo])) { |
|
| 519 | - $srcWidth = $largeur_img[$logo]; |
|
| 520 | - } |
|
| 521 | - if (isset($hauteur_img[$logo])) { |
|
| 522 | - $srcHeight = $hauteur_img[$logo]; |
|
| 523 | - } |
|
| 524 | - if (!$srcWidth or !$srcHeight) { |
|
| 525 | - if (file_exists($logo) |
|
| 526 | - and $srcsize = @getimagesize($logo) |
|
| 527 | - ) { |
|
| 528 | - if (!$srcWidth) { |
|
| 529 | - $largeur_img[$logo] = $srcWidth = $srcsize[0]; |
|
| 530 | - } |
|
| 531 | - if (!$srcHeight) { |
|
| 532 | - $hauteur_img[$logo] = $srcHeight = $srcsize[1]; |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - // $logo peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 536 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 537 | - elseif (@file_exists($f = "$logo.src") |
|
| 538 | - and lire_fichier($f, $valeurs) |
|
| 539 | - and $valeurs = unserialize($valeurs) |
|
| 540 | - ) { |
|
| 541 | - if (!$srcWidth) { |
|
| 542 | - $largeur_img[$logo] = $srcWidth = $valeurs["largeur_dest"]; |
|
| 543 | - } |
|
| 544 | - if (!$srcHeight) { |
|
| 545 | - $hauteur_img[$logo] = $srcHeight = $valeurs["hauteur_dest"]; |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - return array($srcHeight, $srcWidth); |
|
| 493 | + static $largeur_img = array(), $hauteur_img = array(); |
|
| 494 | + $srcWidth = 0; |
|
| 495 | + $srcHeight = 0; |
|
| 496 | + |
|
| 497 | + $logo = extraire_attribut($img, 'src'); |
|
| 498 | + |
|
| 499 | + if (!$logo) { |
|
| 500 | + $logo = $img; |
|
| 501 | + } else { |
|
| 502 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 503 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 507 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 508 | + if (tester_url_absolue($logo)) { |
|
| 509 | + include_spip('inc/distant'); |
|
| 510 | + $fichier = copie_locale($logo); |
|
| 511 | + $logo = $fichier ? _DIR_RACINE . $fichier : $logo; |
|
| 512 | + } |
|
| 513 | + if (($p = strpos($logo, '?')) !== false) { |
|
| 514 | + $logo = substr($logo, 0, $p); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + $srcsize = false; |
|
| 518 | + if (isset($largeur_img[$logo])) { |
|
| 519 | + $srcWidth = $largeur_img[$logo]; |
|
| 520 | + } |
|
| 521 | + if (isset($hauteur_img[$logo])) { |
|
| 522 | + $srcHeight = $hauteur_img[$logo]; |
|
| 523 | + } |
|
| 524 | + if (!$srcWidth or !$srcHeight) { |
|
| 525 | + if (file_exists($logo) |
|
| 526 | + and $srcsize = @getimagesize($logo) |
|
| 527 | + ) { |
|
| 528 | + if (!$srcWidth) { |
|
| 529 | + $largeur_img[$logo] = $srcWidth = $srcsize[0]; |
|
| 530 | + } |
|
| 531 | + if (!$srcHeight) { |
|
| 532 | + $hauteur_img[$logo] = $srcHeight = $srcsize[1]; |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + // $logo peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 536 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 537 | + elseif (@file_exists($f = "$logo.src") |
|
| 538 | + and lire_fichier($f, $valeurs) |
|
| 539 | + and $valeurs = unserialize($valeurs) |
|
| 540 | + ) { |
|
| 541 | + if (!$srcWidth) { |
|
| 542 | + $largeur_img[$logo] = $srcWidth = $valeurs["largeur_dest"]; |
|
| 543 | + } |
|
| 544 | + if (!$srcHeight) { |
|
| 545 | + $hauteur_img[$logo] = $srcHeight = $valeurs["hauteur_dest"]; |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + return array($srcHeight, $srcWidth); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
@@ -565,12 +565,12 @@ discard block |
||
| 565 | 565 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 566 | 566 | **/ |
| 567 | 567 | function largeur($img) { |
| 568 | - if (!$img) { |
|
| 569 | - return; |
|
| 570 | - } |
|
| 571 | - list($h, $l) = taille_image($img); |
|
| 568 | + if (!$img) { |
|
| 569 | + return; |
|
| 570 | + } |
|
| 571 | + list($h, $l) = taille_image($img); |
|
| 572 | 572 | |
| 573 | - return $l; |
|
| 573 | + return $l; |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -587,12 +587,12 @@ discard block |
||
| 587 | 587 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 588 | 588 | **/ |
| 589 | 589 | function hauteur($img) { |
| 590 | - if (!$img) { |
|
| 591 | - return; |
|
| 592 | - } |
|
| 593 | - list($h, $l) = taille_image($img); |
|
| 590 | + if (!$img) { |
|
| 591 | + return; |
|
| 592 | + } |
|
| 593 | + list($h, $l) = taille_image($img); |
|
| 594 | 594 | |
| 595 | - return $h; |
|
| 595 | + return $h; |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | |
@@ -612,11 +612,11 @@ discard block |
||
| 612 | 612 | * @return string |
| 613 | 613 | **/ |
| 614 | 614 | function corriger_entites_html($texte) { |
| 615 | - if (strpos($texte, '&') === false) { |
|
| 616 | - return $texte; |
|
| 617 | - } |
|
| 615 | + if (strpos($texte, '&') === false) { |
|
| 616 | + return $texte; |
|
| 617 | + } |
|
| 618 | 618 | |
| 619 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 619 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -631,11 +631,11 @@ discard block |
||
| 631 | 631 | * @return string |
| 632 | 632 | **/ |
| 633 | 633 | function corriger_toutes_entites_html($texte) { |
| 634 | - if (strpos($texte, '&') === false) { |
|
| 635 | - return $texte; |
|
| 636 | - } |
|
| 634 | + if (strpos($texte, '&') === false) { |
|
| 635 | + return $texte; |
|
| 636 | + } |
|
| 637 | 637 | |
| 638 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 638 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | * @return string |
| 646 | 646 | **/ |
| 647 | 647 | function proteger_amp($texte) { |
| 648 | - return str_replace('&', '&', $texte); |
|
| 648 | + return str_replace('&', '&', $texte); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | |
@@ -676,20 +676,20 @@ discard block |
||
| 676 | 676 | * @return mixed|string |
| 677 | 677 | */ |
| 678 | 678 | function entites_html($texte, $tout = false, $quote = true) { |
| 679 | - if (!is_string($texte) or !$texte |
|
| 680 | - or strpbrk($texte, "&\"'<>") == false |
|
| 681 | - ) { |
|
| 682 | - return $texte; |
|
| 683 | - } |
|
| 684 | - include_spip('inc/texte'); |
|
| 685 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 686 | - $flags |= ENT_HTML401; |
|
| 687 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 688 | - if ($tout) { |
|
| 689 | - return corriger_toutes_entites_html($texte); |
|
| 690 | - } else { |
|
| 691 | - return corriger_entites_html($texte); |
|
| 692 | - } |
|
| 679 | + if (!is_string($texte) or !$texte |
|
| 680 | + or strpbrk($texte, "&\"'<>") == false |
|
| 681 | + ) { |
|
| 682 | + return $texte; |
|
| 683 | + } |
|
| 684 | + include_spip('inc/texte'); |
|
| 685 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 686 | + $flags |= ENT_HTML401; |
|
| 687 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 688 | + if ($tout) { |
|
| 689 | + return corriger_toutes_entites_html($texte); |
|
| 690 | + } else { |
|
| 691 | + return corriger_entites_html($texte); |
|
| 692 | + } |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | /** |
@@ -708,37 +708,37 @@ discard block |
||
| 708 | 708 | * Texte converti |
| 709 | 709 | **/ |
| 710 | 710 | function filtrer_entites($texte) { |
| 711 | - if (strpos($texte, '&') === false) { |
|
| 712 | - return $texte; |
|
| 713 | - } |
|
| 714 | - // filtrer |
|
| 715 | - $texte = html2unicode($texte); |
|
| 716 | - // remettre le tout dans le charset cible |
|
| 717 | - $texte = unicode2charset($texte); |
|
| 718 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 719 | - // (on le faisait deja avec un ") |
|
| 720 | - if (strpos($texte, "&#") !== false) { |
|
| 721 | - $texte = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $texte); |
|
| 722 | - } |
|
| 711 | + if (strpos($texte, '&') === false) { |
|
| 712 | + return $texte; |
|
| 713 | + } |
|
| 714 | + // filtrer |
|
| 715 | + $texte = html2unicode($texte); |
|
| 716 | + // remettre le tout dans le charset cible |
|
| 717 | + $texte = unicode2charset($texte); |
|
| 718 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 719 | + // (on le faisait deja avec un ") |
|
| 720 | + if (strpos($texte, "&#") !== false) { |
|
| 721 | + $texte = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $texte); |
|
| 722 | + } |
|
| 723 | 723 | |
| 724 | - return $texte; |
|
| 724 | + return $texte; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | |
| 728 | 728 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 729 | - /** |
|
| 730 | - * Version sécurisée de filtrer_entites |
|
| 731 | - * |
|
| 732 | - * @uses interdire_scripts() |
|
| 733 | - * @uses filtrer_entites() |
|
| 734 | - * |
|
| 735 | - * @param string $t |
|
| 736 | - * @return string |
|
| 737 | - */ |
|
| 738 | - function filtre_filtrer_entites_dist($t) { |
|
| 739 | - include_spip('inc/texte'); |
|
| 740 | - return interdire_scripts(filtrer_entites($t)); |
|
| 741 | - } |
|
| 729 | + /** |
|
| 730 | + * Version sécurisée de filtrer_entites |
|
| 731 | + * |
|
| 732 | + * @uses interdire_scripts() |
|
| 733 | + * @uses filtrer_entites() |
|
| 734 | + * |
|
| 735 | + * @param string $t |
|
| 736 | + * @return string |
|
| 737 | + */ |
|
| 738 | + function filtre_filtrer_entites_dist($t) { |
|
| 739 | + include_spip('inc/texte'); |
|
| 740 | + return interdire_scripts(filtrer_entites($t)); |
|
| 741 | + } |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | |
@@ -753,18 +753,18 @@ discard block |
||
| 753 | 753 | * @return string|array |
| 754 | 754 | **/ |
| 755 | 755 | function supprimer_caracteres_illegaux($texte) { |
| 756 | - 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"; |
|
| 757 | - static $to = null; |
|
| 756 | + 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"; |
|
| 757 | + static $to = null; |
|
| 758 | 758 | |
| 759 | - if (is_array($texte)) { |
|
| 760 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 761 | - } |
|
| 759 | + if (is_array($texte)) { |
|
| 760 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 761 | + } |
|
| 762 | 762 | |
| 763 | - if (!$to) { |
|
| 764 | - $to = str_repeat('-', strlen($from)); |
|
| 765 | - } |
|
| 763 | + if (!$to) { |
|
| 764 | + $to = str_repeat('-', strlen($from)); |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | - return strtr($texte, $from, $to); |
|
| 767 | + return strtr($texte, $from, $to); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -776,10 +776,10 @@ discard block |
||
| 776 | 776 | * @return string|array |
| 777 | 777 | **/ |
| 778 | 778 | function corriger_caracteres($texte) { |
| 779 | - $texte = corriger_caracteres_windows($texte); |
|
| 780 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 779 | + $texte = corriger_caracteres_windows($texte); |
|
| 780 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 781 | 781 | |
| 782 | - return $texte; |
|
| 782 | + return $texte; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | /** |
@@ -797,40 +797,40 @@ discard block |
||
| 797 | 797 | */ |
| 798 | 798 | function texte_backend($texte) { |
| 799 | 799 | |
| 800 | - static $apostrophe = array("’", "'"); # n'allouer qu'une fois |
|
| 800 | + static $apostrophe = array("’", "'"); # n'allouer qu'une fois |
|
| 801 | 801 | |
| 802 | - // si on a des liens ou des images, les passer en absolu |
|
| 803 | - $texte = liens_absolus($texte); |
|
| 802 | + // si on a des liens ou des images, les passer en absolu |
|
| 803 | + $texte = liens_absolus($texte); |
|
| 804 | 804 | |
| 805 | - // echapper les tags > < |
|
| 806 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 805 | + // echapper les tags > < |
|
| 806 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 807 | 807 | |
| 808 | - // importer les é |
|
| 809 | - $texte = filtrer_entites($texte); |
|
| 808 | + // importer les é |
|
| 809 | + $texte = filtrer_entites($texte); |
|
| 810 | 810 | |
| 811 | - // " -> " et tout ce genre de choses |
|
| 812 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 813 | - $texte = str_replace(" ", " ", $texte); |
|
| 814 | - $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte); |
|
| 815 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 816 | - $texte = entites_html($texte, false, false); |
|
| 817 | - // mais bien echapper les double quotes ! |
|
| 818 | - $texte = str_replace('"', '"', $texte); |
|
| 811 | + // " -> " et tout ce genre de choses |
|
| 812 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 813 | + $texte = str_replace(" ", " ", $texte); |
|
| 814 | + $texte = preg_replace('/\s{2,}/S' . $u, " ", $texte); |
|
| 815 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 816 | + $texte = entites_html($texte, false, false); |
|
| 817 | + // mais bien echapper les double quotes ! |
|
| 818 | + $texte = str_replace('"', '"', $texte); |
|
| 819 | 819 | |
| 820 | - // verifier le charset |
|
| 821 | - $texte = charset2unicode($texte); |
|
| 820 | + // verifier le charset |
|
| 821 | + $texte = charset2unicode($texte); |
|
| 822 | 822 | |
| 823 | - // Caracteres problematiques en iso-latin 1 |
|
| 824 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 825 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 826 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 827 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 828 | - } |
|
| 823 | + // Caracteres problematiques en iso-latin 1 |
|
| 824 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 825 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 826 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 827 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 828 | + } |
|
| 829 | 829 | |
| 830 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 831 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 832 | - // ==> on les remplace par l'entite HTML |
|
| 833 | - return str_replace($apostrophe, "'", $texte); |
|
| 830 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 831 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 832 | + // ==> on les remplace par l'entite HTML |
|
| 833 | + return str_replace($apostrophe, "'", $texte); |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | /** |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | * Texte encodé et quote pour XML |
| 848 | 848 | */ |
| 849 | 849 | function texte_backendq($texte) { |
| 850 | - return addslashes(texte_backend($texte)); |
|
| 850 | + return addslashes(texte_backend($texte)); |
|
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | |
@@ -870,9 +870,9 @@ discard block |
||
| 870 | 870 | * Numéro de titre, sinon chaîne vide |
| 871 | 871 | **/ |
| 872 | 872 | function supprimer_numero($texte) { |
| 873 | - return preg_replace( |
|
| 874 | - ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 875 | - "", $texte); |
|
| 873 | + return preg_replace( |
|
| 874 | + ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 875 | + "", $texte); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | /** |
@@ -895,13 +895,13 @@ discard block |
||
| 895 | 895 | * Numéro de titre, sinon chaîne vide |
| 896 | 896 | **/ |
| 897 | 897 | function recuperer_numero($texte) { |
| 898 | - if (preg_match( |
|
| 899 | - ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 900 | - $texte, $regs)) { |
|
| 901 | - return strval($regs[1]); |
|
| 902 | - } else { |
|
| 903 | - return ''; |
|
| 904 | - } |
|
| 898 | + if (preg_match( |
|
| 899 | + ",^[[:space:]]*([0-9]+)([.)]|" . chr(194) . '?' . chr(176) . ")[[:space:]]+,S", |
|
| 900 | + $texte, $regs)) { |
|
| 901 | + return strval($regs[1]); |
|
| 902 | + } else { |
|
| 903 | + return ''; |
|
| 904 | + } |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | /** |
@@ -928,13 +928,13 @@ discard block |
||
| 928 | 928 | * Texte converti |
| 929 | 929 | **/ |
| 930 | 930 | function supprimer_tags($texte, $rempl = "") { |
| 931 | - $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte); |
|
| 932 | - // ne pas oublier un < final non ferme car coupe |
|
| 933 | - $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte); |
|
| 934 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 935 | - $texte = str_replace('<', '<', $texte); |
|
| 931 | + $texte = preg_replace(",<(!--|\w|/|!\[endif|!\[if)[^>]*>,US", $rempl, $texte); |
|
| 932 | + // ne pas oublier un < final non ferme car coupe |
|
| 933 | + $texte = preg_replace(",<(!--|\w|/).*$,US", $rempl, $texte); |
|
| 934 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 935 | + $texte = str_replace('<', '<', $texte); |
|
| 936 | 936 | |
| 937 | - return $texte; |
|
| 937 | + return $texte; |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | /** |
@@ -957,9 +957,9 @@ discard block |
||
| 957 | 957 | * Texte converti |
| 958 | 958 | **/ |
| 959 | 959 | function echapper_tags($texte, $rempl = "") { |
| 960 | - $texte = preg_replace("/<([^>]*)>/", "<\\1>", $texte); |
|
| 960 | + $texte = preg_replace("/<([^>]*)>/", "<\\1>", $texte); |
|
| 961 | 961 | |
| 962 | - return $texte; |
|
| 962 | + return $texte; |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -980,18 +980,18 @@ discard block |
||
| 980 | 980 | * Texte converti |
| 981 | 981 | **/ |
| 982 | 982 | function textebrut($texte) { |
| 983 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 984 | - $texte = preg_replace('/\s+/S' . $u, " ", $texte); |
|
| 985 | - $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte); |
|
| 986 | - $texte = preg_replace("/^\n+/", "", $texte); |
|
| 987 | - $texte = preg_replace("/\n+$/", "", $texte); |
|
| 988 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 989 | - $texte = supprimer_tags($texte); |
|
| 990 | - $texte = preg_replace("/( | )+/S", " ", $texte); |
|
| 991 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 992 | - $texte = str_replace("’", "'", $texte); |
|
| 983 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 984 | + $texte = preg_replace('/\s+/S' . $u, " ", $texte); |
|
| 985 | + $texte = preg_replace("/<(p|br)( [^>]*)?" . ">/iS", "\n\n", $texte); |
|
| 986 | + $texte = preg_replace("/^\n+/", "", $texte); |
|
| 987 | + $texte = preg_replace("/\n+$/", "", $texte); |
|
| 988 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 989 | + $texte = supprimer_tags($texte); |
|
| 990 | + $texte = preg_replace("/( | )+/S", " ", $texte); |
|
| 991 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 992 | + $texte = str_replace("’", "'", $texte); |
|
| 993 | 993 | |
| 994 | - return $texte; |
|
| 994 | + return $texte; |
|
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | |
@@ -1007,17 +1007,17 @@ discard block |
||
| 1007 | 1007 | * Texte avec liens ouvrants |
| 1008 | 1008 | **/ |
| 1009 | 1009 | function liens_ouvrants($texte) { |
| 1010 | - if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1011 | - $texte, $liens, PREG_SET_ORDER)) { |
|
| 1012 | - foreach ($liens[0] as $a) { |
|
| 1013 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1014 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1015 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1016 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1017 | - } |
|
| 1018 | - } |
|
| 1010 | + if (preg_match_all(",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1011 | + $texte, $liens, PREG_SET_ORDER)) { |
|
| 1012 | + foreach ($liens[0] as $a) { |
|
| 1013 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1014 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1015 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1016 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1017 | + } |
|
| 1018 | + } |
|
| 1019 | 1019 | |
| 1020 | - return $texte; |
|
| 1020 | + return $texte; |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | /** |
@@ -1027,22 +1027,22 @@ discard block |
||
| 1027 | 1027 | * @return string |
| 1028 | 1028 | */ |
| 1029 | 1029 | function liens_nofollow($texte) { |
| 1030 | - if (stripos($texte, "<a") === false) { |
|
| 1031 | - return $texte; |
|
| 1032 | - } |
|
| 1030 | + if (stripos($texte, "<a") === false) { |
|
| 1031 | + return $texte; |
|
| 1032 | + } |
|
| 1033 | 1033 | |
| 1034 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1035 | - foreach ($regs[0] as $a) { |
|
| 1036 | - $rel = extraire_attribut($a, "rel"); |
|
| 1037 | - if (strpos($rel, "nofollow") === false) { |
|
| 1038 | - $rel = "nofollow" . ($rel ? " $rel" : ""); |
|
| 1039 | - $anofollow = inserer_attribut($a, "rel", $rel); |
|
| 1040 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - } |
|
| 1034 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1035 | + foreach ($regs[0] as $a) { |
|
| 1036 | + $rel = extraire_attribut($a, "rel"); |
|
| 1037 | + if (strpos($rel, "nofollow") === false) { |
|
| 1038 | + $rel = "nofollow" . ($rel ? " $rel" : ""); |
|
| 1039 | + $anofollow = inserer_attribut($a, "rel", $rel); |
|
| 1040 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + } |
|
| 1044 | 1044 | |
| 1045 | - return $texte; |
|
| 1045 | + return $texte; |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | /** |
@@ -1061,12 +1061,12 @@ discard block |
||
| 1061 | 1061 | * Texte sans paraghaphes |
| 1062 | 1062 | **/ |
| 1063 | 1063 | function PtoBR($texte) { |
| 1064 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1065 | - $texte = preg_replace("@</p>@iS", "\n", $texte); |
|
| 1066 | - $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte); |
|
| 1067 | - $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte); |
|
| 1064 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1065 | + $texte = preg_replace("@</p>@iS", "\n", $texte); |
|
| 1066 | + $texte = preg_replace("@<p\b.*>@UiS", "<br />", $texte); |
|
| 1067 | + $texte = preg_replace("@^\s*<br />@S" . $u, "", $texte); |
|
| 1068 | 1068 | |
| 1069 | - return $texte; |
|
| 1069 | + return $texte; |
|
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | 1072 | |
@@ -1090,14 +1090,14 @@ discard block |
||
| 1090 | 1090 | * @return string Texte encadré du style CSS |
| 1091 | 1091 | */ |
| 1092 | 1092 | function lignes_longues($texte) { |
| 1093 | - if (!strlen(trim($texte))) { |
|
| 1094 | - return $texte; |
|
| 1095 | - } |
|
| 1096 | - include_spip('inc/texte'); |
|
| 1097 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1098 | - 'div' : 'span'; |
|
| 1093 | + if (!strlen(trim($texte))) { |
|
| 1094 | + return $texte; |
|
| 1095 | + } |
|
| 1096 | + include_spip('inc/texte'); |
|
| 1097 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1098 | + 'div' : 'span'; |
|
| 1099 | 1099 | |
| 1100 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1100 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1101 | 1101 | } |
| 1102 | 1102 | |
| 1103 | 1103 | /** |
@@ -1116,30 +1116,30 @@ discard block |
||
| 1116 | 1116 | * @return string Texte en majuscule |
| 1117 | 1117 | */ |
| 1118 | 1118 | function majuscules($texte) { |
| 1119 | - if (!strlen($texte)) { |
|
| 1120 | - return ''; |
|
| 1121 | - } |
|
| 1119 | + if (!strlen($texte)) { |
|
| 1120 | + return ''; |
|
| 1121 | + } |
|
| 1122 | 1122 | |
| 1123 | - // Cas du turc |
|
| 1124 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1125 | - # remplacer hors des tags et des entites |
|
| 1126 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1127 | - foreach ($regs as $n => $match) { |
|
| 1128 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1129 | - } |
|
| 1130 | - } |
|
| 1123 | + // Cas du turc |
|
| 1124 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1125 | + # remplacer hors des tags et des entites |
|
| 1126 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1127 | + foreach ($regs as $n => $match) { |
|
| 1128 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1129 | + } |
|
| 1130 | + } |
|
| 1131 | 1131 | |
| 1132 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1132 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1133 | 1133 | |
| 1134 | - if ($regs) { |
|
| 1135 | - foreach ($regs as $n => $match) { |
|
| 1136 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1137 | - } |
|
| 1138 | - } |
|
| 1139 | - } |
|
| 1134 | + if ($regs) { |
|
| 1135 | + foreach ($regs as $n => $match) { |
|
| 1136 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1139 | + } |
|
| 1140 | 1140 | |
| 1141 | - // Cas general |
|
| 1142 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1141 | + // Cas general |
|
| 1142 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | /** |
@@ -1157,29 +1157,29 @@ discard block |
||
| 1157 | 1157 | * @return string |
| 1158 | 1158 | **/ |
| 1159 | 1159 | function taille_en_octets($taille) { |
| 1160 | - if (!defined('_KILOBYTE')) { |
|
| 1161 | - /** |
|
| 1162 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1163 | - * |
|
| 1164 | - * @var int |
|
| 1165 | - **/ |
|
| 1166 | - define('_KILOBYTE', 1024); |
|
| 1167 | - } |
|
| 1160 | + if (!defined('_KILOBYTE')) { |
|
| 1161 | + /** |
|
| 1162 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1163 | + * |
|
| 1164 | + * @var int |
|
| 1165 | + **/ |
|
| 1166 | + define('_KILOBYTE', 1024); |
|
| 1167 | + } |
|
| 1168 | 1168 | |
| 1169 | - if ($taille < 1) { |
|
| 1170 | - return ''; |
|
| 1171 | - } |
|
| 1172 | - if ($taille < _KILOBYTE) { |
|
| 1173 | - $taille = _T('taille_octets', array('taille' => $taille)); |
|
| 1174 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1175 | - $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1))); |
|
| 1176 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1177 | - $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1))); |
|
| 1178 | - } else { |
|
| 1179 | - $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2))); |
|
| 1180 | - } |
|
| 1169 | + if ($taille < 1) { |
|
| 1170 | + return ''; |
|
| 1171 | + } |
|
| 1172 | + if ($taille < _KILOBYTE) { |
|
| 1173 | + $taille = _T('taille_octets', array('taille' => $taille)); |
|
| 1174 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1175 | + $taille = _T('taille_ko', array('taille' => round($taille / _KILOBYTE, 1))); |
|
| 1176 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1177 | + $taille = _T('taille_mo', array('taille' => round($taille / _KILOBYTE / _KILOBYTE, 1))); |
|
| 1178 | + } else { |
|
| 1179 | + $taille = _T('taille_go', array('taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2))); |
|
| 1180 | + } |
|
| 1181 | 1181 | |
| 1182 | - return $taille; |
|
| 1182 | + return $taille; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | |
@@ -1201,15 +1201,15 @@ discard block |
||
| 1201 | 1201 | * Texte prêt pour être utilisé en attribut HTML |
| 1202 | 1202 | **/ |
| 1203 | 1203 | function attribut_html($texte, $textebrut = true) { |
| 1204 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1205 | - if ($textebrut) { |
|
| 1206 | - $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte)); |
|
| 1207 | - } |
|
| 1208 | - $texte = texte_backend($texte); |
|
| 1209 | - $texte = str_replace(array("'", '"'), array(''', '"'), $texte); |
|
| 1204 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1205 | + if ($textebrut) { |
|
| 1206 | + $texte = preg_replace(array(",\n,", ",\s(?=\s),msS" . $u), array(" ", ""), textebrut($texte)); |
|
| 1207 | + } |
|
| 1208 | + $texte = texte_backend($texte); |
|
| 1209 | + $texte = str_replace(array("'", '"'), array(''', '"'), $texte); |
|
| 1210 | 1210 | |
| 1211 | - return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&"), |
|
| 1212 | - $texte); |
|
| 1211 | + return preg_replace(array("/&(amp;|#38;)/", "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/"), array("&", "&"), |
|
| 1212 | + $texte); |
|
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | 1215 | |
@@ -1229,12 +1229,12 @@ discard block |
||
| 1229 | 1229 | * URL ou chaîne vide |
| 1230 | 1230 | **/ |
| 1231 | 1231 | function vider_url($url, $entites = true) { |
| 1232 | - # un message pour abs_url |
|
| 1233 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1234 | - $url = trim($url); |
|
| 1235 | - $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1232 | + # un message pour abs_url |
|
| 1233 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1234 | + $url = trim($url); |
|
| 1235 | + $r = ",^(?:" . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1236 | 1236 | |
| 1237 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1237 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | 1240 | |
@@ -1249,10 +1249,10 @@ discard block |
||
| 1249 | 1249 | * @return string Adresse email maquillée |
| 1250 | 1250 | **/ |
| 1251 | 1251 | function antispam($texte) { |
| 1252 | - include_spip('inc/acces'); |
|
| 1253 | - $masque = creer_pass_aleatoire(3); |
|
| 1252 | + include_spip('inc/acces'); |
|
| 1253 | + $masque = creer_pass_aleatoire(3); |
|
| 1254 | 1254 | |
| 1255 | - return preg_replace("/@/", " $masque ", $texte); |
|
| 1255 | + return preg_replace("/@/", " $masque ", $texte); |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | /** |
@@ -1284,12 +1284,12 @@ discard block |
||
| 1284 | 1284 | * True si on a le droit d'accès, false sinon. |
| 1285 | 1285 | **/ |
| 1286 | 1286 | function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1287 | - include_spip('inc/acces'); |
|
| 1288 | - if ($op) { |
|
| 1289 | - $dir .= " $op $args"; |
|
| 1290 | - } |
|
| 1287 | + include_spip('inc/acces'); |
|
| 1288 | + if ($op) { |
|
| 1289 | + $dir .= " $op $args"; |
|
| 1290 | + } |
|
| 1291 | 1291 | |
| 1292 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 1292 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | /** |
@@ -1314,11 +1314,11 @@ discard block |
||
| 1314 | 1314 | * Retourne $texte, sinon $sinon. |
| 1315 | 1315 | **/ |
| 1316 | 1316 | function sinon($texte, $sinon = '') { |
| 1317 | - if ($texte or (!is_array($texte) and strlen($texte))) { |
|
| 1318 | - return $texte; |
|
| 1319 | - } else { |
|
| 1320 | - return $sinon; |
|
| 1321 | - } |
|
| 1317 | + if ($texte or (!is_array($texte) and strlen($texte))) { |
|
| 1318 | + return $texte; |
|
| 1319 | + } else { |
|
| 1320 | + return $sinon; |
|
| 1321 | + } |
|
| 1322 | 1322 | } |
| 1323 | 1323 | |
| 1324 | 1324 | /** |
@@ -1342,7 +1342,7 @@ discard block |
||
| 1342 | 1342 | * @return mixed |
| 1343 | 1343 | **/ |
| 1344 | 1344 | function choixsivide($a, $vide, $pasvide) { |
| 1345 | - return $a ? $pasvide : $vide; |
|
| 1345 | + return $a ? $pasvide : $vide; |
|
| 1346 | 1346 | } |
| 1347 | 1347 | |
| 1348 | 1348 | /** |
@@ -1366,7 +1366,7 @@ discard block |
||
| 1366 | 1366 | * @return mixed |
| 1367 | 1367 | **/ |
| 1368 | 1368 | function choixsiegal($a1, $a2, $v, $f) { |
| 1369 | - return ($a1 == $a2) ? $v : $f; |
|
| 1369 | + return ($a1 == $a2) ? $v : $f; |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | // |
@@ -1385,13 +1385,13 @@ discard block |
||
| 1385 | 1385 | * @return string |
| 1386 | 1386 | **/ |
| 1387 | 1387 | function filtrer_ical($texte) { |
| 1388 | - #include_spip('inc/charsets'); |
|
| 1389 | - $texte = html2unicode($texte); |
|
| 1390 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1391 | - $texte = preg_replace("/\n/", " ", $texte); |
|
| 1392 | - $texte = preg_replace("/,/", "\,", $texte); |
|
| 1388 | + #include_spip('inc/charsets'); |
|
| 1389 | + $texte = html2unicode($texte); |
|
| 1390 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1391 | + $texte = preg_replace("/\n/", " ", $texte); |
|
| 1392 | + $texte = preg_replace("/,/", "\,", $texte); |
|
| 1393 | 1393 | |
| 1394 | - return $texte; |
|
| 1394 | + return $texte; |
|
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | 1397 | |
@@ -1416,53 +1416,53 @@ discard block |
||
| 1416 | 1416 | * @return string |
| 1417 | 1417 | **/ |
| 1418 | 1418 | function post_autobr($texte, $delim = "\n_ ") { |
| 1419 | - if (!function_exists('echappe_html')) { |
|
| 1420 | - include_spip('inc/texte_mini'); |
|
| 1421 | - } |
|
| 1422 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1423 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1424 | - |
|
| 1425 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1426 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1427 | - } else { |
|
| 1428 | - $fin = ''; |
|
| 1429 | - } |
|
| 1430 | - |
|
| 1431 | - $texte = echappe_html($texte, '', true); |
|
| 1432 | - |
|
| 1433 | - // echapper les modeles |
|
| 1434 | - if (strpos($texte, "<") !== false) { |
|
| 1435 | - include_spip('inc/lien'); |
|
| 1436 | - if (defined('_PREG_MODELE')) { |
|
| 1437 | - $preg_modeles = "@" . _PREG_MODELE . "@imsS"; |
|
| 1438 | - $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - $debut = ''; |
|
| 1443 | - $suite = $texte; |
|
| 1444 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1445 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1446 | - $suite = substr($suite, $t); |
|
| 1447 | - $car = substr($suite, 0, 1); |
|
| 1448 | - if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}") |
|
| 1449 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1450 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1451 | - ) { |
|
| 1452 | - $debut .= $delim; |
|
| 1453 | - } else { |
|
| 1454 | - $debut .= "\n"; |
|
| 1455 | - } |
|
| 1456 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1457 | - $debut .= $regs[0]; |
|
| 1458 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1459 | - } |
|
| 1460 | - } |
|
| 1461 | - $texte = $debut . $suite; |
|
| 1462 | - |
|
| 1463 | - $texte = echappe_retour($texte); |
|
| 1464 | - |
|
| 1465 | - return $texte . $fin; |
|
| 1419 | + if (!function_exists('echappe_html')) { |
|
| 1420 | + include_spip('inc/texte_mini'); |
|
| 1421 | + } |
|
| 1422 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1423 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1424 | + |
|
| 1425 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1426 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1427 | + } else { |
|
| 1428 | + $fin = ''; |
|
| 1429 | + } |
|
| 1430 | + |
|
| 1431 | + $texte = echappe_html($texte, '', true); |
|
| 1432 | + |
|
| 1433 | + // echapper les modeles |
|
| 1434 | + if (strpos($texte, "<") !== false) { |
|
| 1435 | + include_spip('inc/lien'); |
|
| 1436 | + if (defined('_PREG_MODELE')) { |
|
| 1437 | + $preg_modeles = "@" . _PREG_MODELE . "@imsS"; |
|
| 1438 | + $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + $debut = ''; |
|
| 1443 | + $suite = $texte; |
|
| 1444 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1445 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1446 | + $suite = substr($suite, $t); |
|
| 1447 | + $car = substr($suite, 0, 1); |
|
| 1448 | + if (($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> "|") and ($car <> "}") |
|
| 1449 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1450 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1451 | + ) { |
|
| 1452 | + $debut .= $delim; |
|
| 1453 | + } else { |
|
| 1454 | + $debut .= "\n"; |
|
| 1455 | + } |
|
| 1456 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1457 | + $debut .= $regs[0]; |
|
| 1458 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1459 | + } |
|
| 1460 | + } |
|
| 1461 | + $texte = $debut . $suite; |
|
| 1462 | + |
|
| 1463 | + $texte = echappe_retour($texte); |
|
| 1464 | + |
|
| 1465 | + return $texte . $fin; |
|
| 1466 | 1466 | } |
| 1467 | 1467 | |
| 1468 | 1468 | |
@@ -1503,46 +1503,46 @@ discard block |
||
| 1503 | 1503 | * @return string |
| 1504 | 1504 | **/ |
| 1505 | 1505 | function extraire_idiome($letexte, $lang = null, $options = array()) { |
| 1506 | - static $traduire = false; |
|
| 1507 | - if ($letexte |
|
| 1508 | - and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1509 | - ) { |
|
| 1510 | - if (!$traduire) { |
|
| 1511 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 1512 | - include_spip('inc/lang'); |
|
| 1513 | - } |
|
| 1514 | - if (!$lang) { |
|
| 1515 | - $lang = $GLOBALS['spip_lang']; |
|
| 1516 | - } |
|
| 1517 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1518 | - if (is_bool($options)) { |
|
| 1519 | - $options = array('echappe_span' => $options); |
|
| 1520 | - } |
|
| 1521 | - if (!isset($options['echappe_span'])) { |
|
| 1522 | - $options = array_merge($options, array('echappe_span' => false)); |
|
| 1523 | - } |
|
| 1524 | - |
|
| 1525 | - foreach ($regs as $reg) { |
|
| 1526 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1527 | - $desc = $traduire($cle, $lang, true); |
|
| 1528 | - $l = $desc->langue; |
|
| 1529 | - // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1530 | - if (strlen($desc->texte)) { |
|
| 1531 | - $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1532 | - if ($l !== $lang) { |
|
| 1533 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1534 | - } |
|
| 1535 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1536 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1537 | - } |
|
| 1538 | - if (!$options['echappe_span']) { |
|
| 1539 | - $trad = echappe_retour($trad, 'idiome'); |
|
| 1540 | - } |
|
| 1541 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1542 | - } |
|
| 1543 | - } |
|
| 1544 | - } |
|
| 1545 | - return $letexte; |
|
| 1506 | + static $traduire = false; |
|
| 1507 | + if ($letexte |
|
| 1508 | + and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1509 | + ) { |
|
| 1510 | + if (!$traduire) { |
|
| 1511 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 1512 | + include_spip('inc/lang'); |
|
| 1513 | + } |
|
| 1514 | + if (!$lang) { |
|
| 1515 | + $lang = $GLOBALS['spip_lang']; |
|
| 1516 | + } |
|
| 1517 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1518 | + if (is_bool($options)) { |
|
| 1519 | + $options = array('echappe_span' => $options); |
|
| 1520 | + } |
|
| 1521 | + if (!isset($options['echappe_span'])) { |
|
| 1522 | + $options = array_merge($options, array('echappe_span' => false)); |
|
| 1523 | + } |
|
| 1524 | + |
|
| 1525 | + foreach ($regs as $reg) { |
|
| 1526 | + $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1527 | + $desc = $traduire($cle, $lang, true); |
|
| 1528 | + $l = $desc->langue; |
|
| 1529 | + // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1530 | + if (strlen($desc->texte)) { |
|
| 1531 | + $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1532 | + if ($l !== $lang) { |
|
| 1533 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1534 | + } |
|
| 1535 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1536 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1537 | + } |
|
| 1538 | + if (!$options['echappe_span']) { |
|
| 1539 | + $trad = echappe_retour($trad, 'idiome'); |
|
| 1540 | + } |
|
| 1541 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1542 | + } |
|
| 1543 | + } |
|
| 1544 | + } |
|
| 1545 | + return $letexte; |
|
| 1546 | 1546 | } |
| 1547 | 1547 | |
| 1548 | 1548 | /** |
@@ -1594,64 +1594,64 @@ discard block |
||
| 1594 | 1594 | **/ |
| 1595 | 1595 | function extraire_multi($letexte, $lang = null, $options = array()) { |
| 1596 | 1596 | |
| 1597 | - if ($letexte |
|
| 1598 | - and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1599 | - ) { |
|
| 1600 | - if (!$lang) { |
|
| 1601 | - $lang = $GLOBALS['spip_lang']; |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1605 | - if (is_bool($options)) { |
|
| 1606 | - $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT); |
|
| 1607 | - } |
|
| 1608 | - if (!isset($options['echappe_span'])) { |
|
| 1609 | - $options = array_merge($options, array('echappe_span' => false)); |
|
| 1610 | - } |
|
| 1611 | - if (!isset($options['lang_defaut'])) { |
|
| 1612 | - $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT)); |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - include_spip('inc/lang'); |
|
| 1616 | - foreach ($regs as $reg) { |
|
| 1617 | - // chercher la version de la langue courante |
|
| 1618 | - $trads = extraire_trads($reg[1]); |
|
| 1619 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 1620 | - $trad = $trads[$l]; |
|
| 1621 | - } else { |
|
| 1622 | - if ($options['lang_defaut'] == 'aucune') { |
|
| 1623 | - $trad = ''; |
|
| 1624 | - } else { |
|
| 1625 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1626 | - // ou la premiere dispo |
|
| 1627 | - // mais typographier le texte selon les regles de celle-ci |
|
| 1628 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 1629 | - if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1630 | - $l = key($trads); |
|
| 1631 | - } |
|
| 1632 | - $trad = $trads[$l]; |
|
| 1633 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1634 | - $trad = $typographie($trad); |
|
| 1635 | - // Tester si on echappe en span ou en div |
|
| 1636 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1637 | - include_spip('inc/texte'); |
|
| 1638 | - $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad)); |
|
| 1639 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1640 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1641 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1642 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1643 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1644 | - } |
|
| 1645 | - if (!$options['echappe_span']) { |
|
| 1646 | - $trad = echappe_retour($trad, 'multi'); |
|
| 1647 | - } |
|
| 1648 | - } |
|
| 1649 | - } |
|
| 1650 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1651 | - } |
|
| 1652 | - } |
|
| 1653 | - |
|
| 1654 | - return $letexte; |
|
| 1597 | + if ($letexte |
|
| 1598 | + and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1599 | + ) { |
|
| 1600 | + if (!$lang) { |
|
| 1601 | + $lang = $GLOBALS['spip_lang']; |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1605 | + if (is_bool($options)) { |
|
| 1606 | + $options = array('echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT); |
|
| 1607 | + } |
|
| 1608 | + if (!isset($options['echappe_span'])) { |
|
| 1609 | + $options = array_merge($options, array('echappe_span' => false)); |
|
| 1610 | + } |
|
| 1611 | + if (!isset($options['lang_defaut'])) { |
|
| 1612 | + $options = array_merge($options, array('lang_defaut' => _LANGUE_PAR_DEFAUT)); |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + include_spip('inc/lang'); |
|
| 1616 | + foreach ($regs as $reg) { |
|
| 1617 | + // chercher la version de la langue courante |
|
| 1618 | + $trads = extraire_trads($reg[1]); |
|
| 1619 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 1620 | + $trad = $trads[$l]; |
|
| 1621 | + } else { |
|
| 1622 | + if ($options['lang_defaut'] == 'aucune') { |
|
| 1623 | + $trad = ''; |
|
| 1624 | + } else { |
|
| 1625 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1626 | + // ou la premiere dispo |
|
| 1627 | + // mais typographier le texte selon les regles de celle-ci |
|
| 1628 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 1629 | + if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1630 | + $l = key($trads); |
|
| 1631 | + } |
|
| 1632 | + $trad = $trads[$l]; |
|
| 1633 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1634 | + $trad = $typographie($trad); |
|
| 1635 | + // Tester si on echappe en span ou en div |
|
| 1636 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1637 | + include_spip('inc/texte'); |
|
| 1638 | + $trad_propre = preg_replace(",(^<p[^>]*>|</p>$),Uims", "", propre($trad)); |
|
| 1639 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1640 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1641 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1642 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1643 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1644 | + } |
|
| 1645 | + if (!$options['echappe_span']) { |
|
| 1646 | + $trad = echappe_retour($trad, 'multi'); |
|
| 1647 | + } |
|
| 1648 | + } |
|
| 1649 | + } |
|
| 1650 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1651 | + } |
|
| 1652 | + } |
|
| 1653 | + |
|
| 1654 | + return $letexte; |
|
| 1655 | 1655 | } |
| 1656 | 1656 | |
| 1657 | 1657 | /** |
@@ -1667,20 +1667,20 @@ discard block |
||
| 1667 | 1667 | * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
| 1668 | 1668 | **/ |
| 1669 | 1669 | function extraire_trads($bloc) { |
| 1670 | - $lang = ''; |
|
| 1670 | + $lang = ''; |
|
| 1671 | 1671 | // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ |
| 1672 | 1672 | // while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) { |
| 1673 | - while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) { |
|
| 1674 | - $texte = trim($regs[1]); |
|
| 1675 | - if ($texte or $lang) { |
|
| 1676 | - $trads[$lang] = $texte; |
|
| 1677 | - } |
|
| 1678 | - $bloc = substr($bloc, strlen($regs[0])); |
|
| 1679 | - $lang = $regs[2]; |
|
| 1680 | - } |
|
| 1681 | - $trads[$lang] = $bloc; |
|
| 1673 | + while (preg_match("/^(.*?)[\[]([a-z_]+)[\]]/siS", $bloc, $regs)) { |
|
| 1674 | + $texte = trim($regs[1]); |
|
| 1675 | + if ($texte or $lang) { |
|
| 1676 | + $trads[$lang] = $texte; |
|
| 1677 | + } |
|
| 1678 | + $bloc = substr($bloc, strlen($regs[0])); |
|
| 1679 | + $lang = $regs[2]; |
|
| 1680 | + } |
|
| 1681 | + $trads[$lang] = $bloc; |
|
| 1682 | 1682 | |
| 1683 | - return $trads; |
|
| 1683 | + return $trads; |
|
| 1684 | 1684 | } |
| 1685 | 1685 | |
| 1686 | 1686 | |
@@ -1691,7 +1691,7 @@ discard block |
||
| 1691 | 1691 | * @return string L'initiale en majuscule |
| 1692 | 1692 | */ |
| 1693 | 1693 | function filtre_initiale($nom) { |
| 1694 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1694 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1695 | 1695 | } |
| 1696 | 1696 | |
| 1697 | 1697 | |
@@ -1736,33 +1736,33 @@ discard block |
||
| 1736 | 1736 | * - null (interne) : si on empile |
| 1737 | 1737 | **/ |
| 1738 | 1738 | function unique($donnee, $famille = '', $cpt = false) { |
| 1739 | - static $mem = array(); |
|
| 1740 | - // permettre de vider la pile et de la restaurer |
|
| 1741 | - // pour le calcul de introduction... |
|
| 1742 | - if ($famille == '_spip_raz_') { |
|
| 1743 | - $tmp = $mem; |
|
| 1744 | - $mem = array(); |
|
| 1745 | - |
|
| 1746 | - return $tmp; |
|
| 1747 | - } elseif ($famille == '_spip_set_') { |
|
| 1748 | - $mem = $donnee; |
|
| 1749 | - |
|
| 1750 | - return; |
|
| 1751 | - } |
|
| 1752 | - // eviter une notice |
|
| 1753 | - if (!isset($mem[$famille])) { |
|
| 1754 | - $mem[$famille] = array(); |
|
| 1755 | - } |
|
| 1756 | - if ($cpt) { |
|
| 1757 | - return count($mem[$famille]); |
|
| 1758 | - } |
|
| 1759 | - // eviter une notice |
|
| 1760 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1761 | - $mem[$famille][$donnee] = 0; |
|
| 1762 | - } |
|
| 1763 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1764 | - return $donnee; |
|
| 1765 | - } |
|
| 1739 | + static $mem = array(); |
|
| 1740 | + // permettre de vider la pile et de la restaurer |
|
| 1741 | + // pour le calcul de introduction... |
|
| 1742 | + if ($famille == '_spip_raz_') { |
|
| 1743 | + $tmp = $mem; |
|
| 1744 | + $mem = array(); |
|
| 1745 | + |
|
| 1746 | + return $tmp; |
|
| 1747 | + } elseif ($famille == '_spip_set_') { |
|
| 1748 | + $mem = $donnee; |
|
| 1749 | + |
|
| 1750 | + return; |
|
| 1751 | + } |
|
| 1752 | + // eviter une notice |
|
| 1753 | + if (!isset($mem[$famille])) { |
|
| 1754 | + $mem[$famille] = array(); |
|
| 1755 | + } |
|
| 1756 | + if ($cpt) { |
|
| 1757 | + return count($mem[$famille]); |
|
| 1758 | + } |
|
| 1759 | + // eviter une notice |
|
| 1760 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1761 | + $mem[$famille][$donnee] = 0; |
|
| 1762 | + } |
|
| 1763 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1764 | + return $donnee; |
|
| 1765 | + } |
|
| 1766 | 1766 | } |
| 1767 | 1767 | |
| 1768 | 1768 | |
@@ -1790,18 +1790,18 @@ discard block |
||
| 1790 | 1790 | * Une des valeurs en fonction du compteur. |
| 1791 | 1791 | **/ |
| 1792 | 1792 | function alterner($i) { |
| 1793 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1794 | - $num = func_num_args(); |
|
| 1795 | - $args = func_get_args(); |
|
| 1793 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1794 | + $num = func_num_args(); |
|
| 1795 | + $args = func_get_args(); |
|
| 1796 | 1796 | |
| 1797 | - if ($num == 2 && is_array($args[1])) { |
|
| 1798 | - $args = $args[1]; |
|
| 1799 | - array_unshift($args, ''); |
|
| 1800 | - $num = count($args); |
|
| 1801 | - } |
|
| 1797 | + if ($num == 2 && is_array($args[1])) { |
|
| 1798 | + $args = $args[1]; |
|
| 1799 | + array_unshift($args, ''); |
|
| 1800 | + $num = count($args); |
|
| 1801 | + } |
|
| 1802 | 1802 | |
| 1803 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1804 | - return $args[(intval($i) - 1) % ($num - 1) + 1]; |
|
| 1803 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1804 | + return $args[(intval($i) - 1) % ($num - 1) + 1]; |
|
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | 1807 | |
@@ -1826,46 +1826,46 @@ discard block |
||
| 1826 | 1826 | * - Tableau complet (si 2e argument) |
| 1827 | 1827 | **/ |
| 1828 | 1828 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1829 | - if (is_array($balise)) { |
|
| 1830 | - array_walk( |
|
| 1831 | - $balise, |
|
| 1832 | - function(&$a, $key, $t){ |
|
| 1833 | - $a = extraire_attribut($a, $t); |
|
| 1834 | - }, |
|
| 1835 | - $attribut |
|
| 1836 | - ); |
|
| 1837 | - |
|
| 1838 | - return $balise; |
|
| 1839 | - } |
|
| 1840 | - if (preg_match( |
|
| 1841 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1842 | - . $attribut |
|
| 1843 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1844 | - |
|
| 1845 | - $balise, $r)) { |
|
| 1846 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1847 | - $r[4] = substr($r[3], 1, -1); |
|
| 1848 | - $r[3] = $r[3][0]; |
|
| 1849 | - } elseif ($r[3] !== '') { |
|
| 1850 | - $r[4] = $r[3]; |
|
| 1851 | - $r[3] = ''; |
|
| 1852 | - } else { |
|
| 1853 | - $r[4] = trim($r[2]); |
|
| 1854 | - } |
|
| 1855 | - $att = $r[4]; |
|
| 1856 | - if (strpos($att, "&#") !== false) { |
|
| 1857 | - $att = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $att); |
|
| 1858 | - } |
|
| 1859 | - $att = filtrer_entites($att); |
|
| 1860 | - } else { |
|
| 1861 | - $att = null; |
|
| 1862 | - } |
|
| 1863 | - |
|
| 1864 | - if ($complet) { |
|
| 1865 | - return array($att, $r); |
|
| 1866 | - } else { |
|
| 1867 | - return $att; |
|
| 1868 | - } |
|
| 1829 | + if (is_array($balise)) { |
|
| 1830 | + array_walk( |
|
| 1831 | + $balise, |
|
| 1832 | + function(&$a, $key, $t){ |
|
| 1833 | + $a = extraire_attribut($a, $t); |
|
| 1834 | + }, |
|
| 1835 | + $attribut |
|
| 1836 | + ); |
|
| 1837 | + |
|
| 1838 | + return $balise; |
|
| 1839 | + } |
|
| 1840 | + if (preg_match( |
|
| 1841 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1842 | + . $attribut |
|
| 1843 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1844 | + |
|
| 1845 | + $balise, $r)) { |
|
| 1846 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1847 | + $r[4] = substr($r[3], 1, -1); |
|
| 1848 | + $r[3] = $r[3][0]; |
|
| 1849 | + } elseif ($r[3] !== '') { |
|
| 1850 | + $r[4] = $r[3]; |
|
| 1851 | + $r[3] = ''; |
|
| 1852 | + } else { |
|
| 1853 | + $r[4] = trim($r[2]); |
|
| 1854 | + } |
|
| 1855 | + $att = $r[4]; |
|
| 1856 | + if (strpos($att, "&#") !== false) { |
|
| 1857 | + $att = str_replace(array("'", "'", """, """), array("'", "'", '"', '"'), $att); |
|
| 1858 | + } |
|
| 1859 | + $att = filtrer_entites($att); |
|
| 1860 | + } else { |
|
| 1861 | + $att = null; |
|
| 1862 | + } |
|
| 1863 | + |
|
| 1864 | + if ($complet) { |
|
| 1865 | + return array($att, $r); |
|
| 1866 | + } else { |
|
| 1867 | + return $att; |
|
| 1868 | + } |
|
| 1869 | 1869 | } |
| 1870 | 1870 | |
| 1871 | 1871 | /** |
@@ -1897,37 +1897,37 @@ discard block |
||
| 1897 | 1897 | * Code html modifié |
| 1898 | 1898 | **/ |
| 1899 | 1899 | function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) { |
| 1900 | - // preparer l'attribut |
|
| 1901 | - // supprimer les etc mais pas les balises html |
|
| 1902 | - // qui ont un sens dans un attribut value d'un input |
|
| 1903 | - if ($proteger) { |
|
| 1904 | - $val = attribut_html($val, false); |
|
| 1905 | - } |
|
| 1906 | - |
|
| 1907 | - // echapper les ' pour eviter tout bug |
|
| 1908 | - $val = str_replace("'", "'", $val); |
|
| 1909 | - if ($vider and strlen($val) == 0) { |
|
| 1910 | - $insert = ''; |
|
| 1911 | - } else { |
|
| 1912 | - $insert = " $attribut='$val'"; |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 1916 | - |
|
| 1917 | - if ($old !== null) { |
|
| 1918 | - // Remplacer l'ancien attribut du meme nom |
|
| 1919 | - $balise = $r[1] . $insert . $r[5]; |
|
| 1920 | - } else { |
|
| 1921 | - // preferer une balise " />" (comme <img />) |
|
| 1922 | - if (preg_match(',/>,', $balise)) { |
|
| 1923 | - $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1); |
|
| 1924 | - } // sinon une balise <a ...> ... </a> |
|
| 1925 | - else { |
|
| 1926 | - $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1); |
|
| 1927 | - } |
|
| 1928 | - } |
|
| 1929 | - |
|
| 1930 | - return $balise; |
|
| 1900 | + // preparer l'attribut |
|
| 1901 | + // supprimer les etc mais pas les balises html |
|
| 1902 | + // qui ont un sens dans un attribut value d'un input |
|
| 1903 | + if ($proteger) { |
|
| 1904 | + $val = attribut_html($val, false); |
|
| 1905 | + } |
|
| 1906 | + |
|
| 1907 | + // echapper les ' pour eviter tout bug |
|
| 1908 | + $val = str_replace("'", "'", $val); |
|
| 1909 | + if ($vider and strlen($val) == 0) { |
|
| 1910 | + $insert = ''; |
|
| 1911 | + } else { |
|
| 1912 | + $insert = " $attribut='$val'"; |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 1916 | + |
|
| 1917 | + if ($old !== null) { |
|
| 1918 | + // Remplacer l'ancien attribut du meme nom |
|
| 1919 | + $balise = $r[1] . $insert . $r[5]; |
|
| 1920 | + } else { |
|
| 1921 | + // preferer une balise " />" (comme <img />) |
|
| 1922 | + if (preg_match(',/>,', $balise)) { |
|
| 1923 | + $balise = preg_replace(",\s?/>,S", $insert . " />", $balise, 1); |
|
| 1924 | + } // sinon une balise <a ...> ... </a> |
|
| 1925 | + else { |
|
| 1926 | + $balise = preg_replace(",\s?>,S", $insert . ">", $balise, 1); |
|
| 1927 | + } |
|
| 1928 | + } |
|
| 1929 | + |
|
| 1930 | + return $balise; |
|
| 1931 | 1931 | } |
| 1932 | 1932 | |
| 1933 | 1933 | /** |
@@ -1945,7 +1945,7 @@ discard block |
||
| 1945 | 1945 | * @return string Code HTML sans l'attribut |
| 1946 | 1946 | **/ |
| 1947 | 1947 | function vider_attribut($balise, $attribut) { |
| 1948 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 1948 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 1949 | 1949 | } |
| 1950 | 1950 | |
| 1951 | 1951 | |
@@ -1957,9 +1957,9 @@ discard block |
||
| 1957 | 1957 | * @return string |
| 1958 | 1958 | */ |
| 1959 | 1959 | function tester_config($id, $mode = '') { |
| 1960 | - include_spip('action/inscrire_auteur'); |
|
| 1960 | + include_spip('action/inscrire_auteur'); |
|
| 1961 | 1961 | |
| 1962 | - return tester_statut_inscription($mode, $id); |
|
| 1962 | + return tester_statut_inscription($mode, $id); |
|
| 1963 | 1963 | } |
| 1964 | 1964 | |
| 1965 | 1965 | // |
@@ -1984,7 +1984,7 @@ discard block |
||
| 1984 | 1984 | * @return int $a+$b |
| 1985 | 1985 | **/ |
| 1986 | 1986 | function plus($a, $b) { |
| 1987 | - return $a + $b; |
|
| 1987 | + return $a + $b; |
|
| 1988 | 1988 | } |
| 1989 | 1989 | function strplus($a, $b) {return strize('plus', $a, $b);} |
| 1990 | 1990 | /** |
@@ -2003,7 +2003,7 @@ discard block |
||
| 2003 | 2003 | * @return int $a-$b |
| 2004 | 2004 | **/ |
| 2005 | 2005 | function moins($a, $b) { |
| 2006 | - return $a - $b; |
|
| 2006 | + return $a - $b; |
|
| 2007 | 2007 | } |
| 2008 | 2008 | function strmoins($a, $b) {return strize('moins', $a, $b);} |
| 2009 | 2009 | |
@@ -2024,7 +2024,7 @@ discard block |
||
| 2024 | 2024 | * @return int $a*$b |
| 2025 | 2025 | **/ |
| 2026 | 2026 | function mult($a, $b) { |
| 2027 | - return $a * $b; |
|
| 2027 | + return $a * $b; |
|
| 2028 | 2028 | } |
| 2029 | 2029 | function strmult($a, $b) {return strize('mult', $a, $b);} |
| 2030 | 2030 | |
@@ -2045,7 +2045,7 @@ discard block |
||
| 2045 | 2045 | * @return int $a/$b (ou 0 si $b est nul) |
| 2046 | 2046 | **/ |
| 2047 | 2047 | function div($a, $b) { |
| 2048 | - return $b ? $a / $b : 0; |
|
| 2048 | + return $b ? $a / $b : 0; |
|
| 2049 | 2049 | } |
| 2050 | 2050 | function strdiv($a, $b) {return strize('div', $a, $b);} |
| 2051 | 2051 | |
@@ -2067,7 +2067,7 @@ discard block |
||
| 2067 | 2067 | * @return int ($nb % $mod) + $add |
| 2068 | 2068 | **/ |
| 2069 | 2069 | function modulo($nb, $mod, $add = 0) { |
| 2070 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2070 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2071 | 2071 | } |
| 2072 | 2072 | |
| 2073 | 2073 | |
@@ -2082,24 +2082,24 @@ discard block |
||
| 2082 | 2082 | * - true sinon |
| 2083 | 2083 | **/ |
| 2084 | 2084 | function nom_acceptable($nom) { |
| 2085 | - if (!is_string($nom)) { |
|
| 2086 | - return false; |
|
| 2087 | - } |
|
| 2088 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2089 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2090 | - } |
|
| 2091 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2092 | - foreach ($tags_acceptes as $tag) { |
|
| 2093 | - if (strlen($tag)) { |
|
| 2094 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2095 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2096 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2097 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2098 | - } |
|
| 2099 | - } |
|
| 2100 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2085 | + if (!is_string($nom)) { |
|
| 2086 | + return false; |
|
| 2087 | + } |
|
| 2088 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2089 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2090 | + } |
|
| 2091 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2092 | + foreach ($tags_acceptes as $tag) { |
|
| 2093 | + if (strlen($tag)) { |
|
| 2094 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2095 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2096 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2097 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2098 | + } |
|
| 2099 | + } |
|
| 2100 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2101 | 2101 | |
| 2102 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2102 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2103 | 2103 | } |
| 2104 | 2104 | |
| 2105 | 2105 | |
@@ -2113,29 +2113,29 @@ discard block |
||
| 2113 | 2113 | * - la normalisation de la dernière adresse donnée sinon |
| 2114 | 2114 | **/ |
| 2115 | 2115 | function email_valide($adresses) { |
| 2116 | - // eviter d'injecter n'importe quoi dans preg_match |
|
| 2117 | - if (!is_string($adresses)) { |
|
| 2118 | - return false; |
|
| 2119 | - } |
|
| 2116 | + // eviter d'injecter n'importe quoi dans preg_match |
|
| 2117 | + if (!is_string($adresses)) { |
|
| 2118 | + return false; |
|
| 2119 | + } |
|
| 2120 | 2120 | |
| 2121 | - // Si c'est un spammeur autant arreter tout de suite |
|
| 2122 | - if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) { |
|
| 2123 | - spip_log("Tentative d'injection de mail : $adresses"); |
|
| 2121 | + // Si c'est un spammeur autant arreter tout de suite |
|
| 2122 | + if (preg_match(",[\n\r].*(MIME|multipart|Content-),i", $adresses)) { |
|
| 2123 | + spip_log("Tentative d'injection de mail : $adresses"); |
|
| 2124 | 2124 | |
| 2125 | - return false; |
|
| 2126 | - } |
|
| 2125 | + return false; |
|
| 2126 | + } |
|
| 2127 | 2127 | |
| 2128 | - foreach (explode(',', $adresses) as $v) { |
|
| 2129 | - // nettoyer certains formats |
|
| 2130 | - // "Marie Toto <[email protected]>" |
|
| 2131 | - $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v)); |
|
| 2132 | - // RFC 822 |
|
| 2133 | - if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) { |
|
| 2134 | - return false; |
|
| 2135 | - } |
|
| 2136 | - } |
|
| 2128 | + foreach (explode(',', $adresses) as $v) { |
|
| 2129 | + // nettoyer certains formats |
|
| 2130 | + // "Marie Toto <[email protected]>" |
|
| 2131 | + $adresse = trim(preg_replace(",^[^<>\"]*<([^<>\"]+)>$,i", "\\1", $v)); |
|
| 2132 | + // RFC 822 |
|
| 2133 | + if (!preg_match('#^[^()<>@,;:\\"/[:space:]]+(@([-_0-9a-z]+\.)*[-_0-9a-z]+)$#i', $adresse)) { |
|
| 2134 | + return false; |
|
| 2135 | + } |
|
| 2136 | + } |
|
| 2137 | 2137 | |
| 2138 | - return $adresse; |
|
| 2138 | + return $adresse; |
|
| 2139 | 2139 | } |
| 2140 | 2140 | |
| 2141 | 2141 | /** |
@@ -2149,20 +2149,20 @@ discard block |
||
| 2149 | 2149 | * @return string Texte |
| 2150 | 2150 | **/ |
| 2151 | 2151 | function afficher_enclosures($tags) { |
| 2152 | - $s = array(); |
|
| 2153 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2154 | - if (extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2155 | - and $t = extraire_attribut($tag, 'href') |
|
| 2156 | - ) { |
|
| 2157 | - $s[] = preg_replace(',>[^<]+</a>,S', |
|
| 2158 | - '>' |
|
| 2159 | - . http_img_pack('attachment-16.png', $t, |
|
| 2160 | - 'title="' . attribut_html($t) . '"') |
|
| 2161 | - . '</a>', $tag); |
|
| 2162 | - } |
|
| 2163 | - } |
|
| 2152 | + $s = array(); |
|
| 2153 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2154 | + if (extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2155 | + and $t = extraire_attribut($tag, 'href') |
|
| 2156 | + ) { |
|
| 2157 | + $s[] = preg_replace(',>[^<]+</a>,S', |
|
| 2158 | + '>' |
|
| 2159 | + . http_img_pack('attachment-16.png', $t, |
|
| 2160 | + 'title="' . attribut_html($t) . '"') |
|
| 2161 | + . '</a>', $tag); |
|
| 2162 | + } |
|
| 2163 | + } |
|
| 2164 | 2164 | |
| 2165 | - return join(' ', $s); |
|
| 2165 | + return join(' ', $s); |
|
| 2166 | 2166 | } |
| 2167 | 2167 | |
| 2168 | 2168 | /** |
@@ -2177,15 +2177,15 @@ discard block |
||
| 2177 | 2177 | * @return string Liens trouvés |
| 2178 | 2178 | **/ |
| 2179 | 2179 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2180 | - $s = array(); |
|
| 2181 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2182 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2183 | - if (strstr(",$rels,", ",$rel,")) { |
|
| 2184 | - $s[] = $tag; |
|
| 2185 | - } |
|
| 2186 | - } |
|
| 2180 | + $s = array(); |
|
| 2181 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2182 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2183 | + if (strstr(",$rels,", ",$rel,")) { |
|
| 2184 | + $s[] = $tag; |
|
| 2185 | + } |
|
| 2186 | + } |
|
| 2187 | 2187 | |
| 2188 | - return join(', ', $s); |
|
| 2188 | + return join(', ', $s); |
|
| 2189 | 2189 | } |
| 2190 | 2190 | |
| 2191 | 2191 | |
@@ -2207,21 +2207,21 @@ discard block |
||
| 2207 | 2207 | * @return string Tag HTML `<a>` avec microformat. |
| 2208 | 2208 | **/ |
| 2209 | 2209 | function enclosure2microformat($e) { |
| 2210 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2211 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2212 | - } |
|
| 2213 | - $type = extraire_attribut($e, 'type'); |
|
| 2214 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2215 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2216 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2217 | - } |
|
| 2218 | - $fichier = basename($url); |
|
| 2210 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2211 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2212 | + } |
|
| 2213 | + $type = extraire_attribut($e, 'type'); |
|
| 2214 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2215 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2216 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2217 | + } |
|
| 2218 | + $fichier = basename($url); |
|
| 2219 | 2219 | |
| 2220 | - return '<a rel="enclosure"' |
|
| 2221 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2222 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2223 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2224 | - . '>' . $fichier . '</a>'; |
|
| 2220 | + return '<a rel="enclosure"' |
|
| 2221 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2222 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2223 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2224 | + . '>' . $fichier . '</a>'; |
|
| 2225 | 2225 | } |
| 2226 | 2226 | |
| 2227 | 2227 | /** |
@@ -2239,24 +2239,24 @@ discard block |
||
| 2239 | 2239 | * @return string Tags RSS `<enclosure>`. |
| 2240 | 2240 | **/ |
| 2241 | 2241 | function microformat2enclosure($tags) { |
| 2242 | - $enclosures = array(); |
|
| 2243 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2244 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2245 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2246 | - $type = extraire_attribut($e, 'type'); |
|
| 2247 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2248 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2249 | - } # vieux data |
|
| 2250 | - $fichier = basename($url); |
|
| 2251 | - $enclosures[] = '<enclosure' |
|
| 2252 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2253 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2254 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2255 | - . ' />'; |
|
| 2256 | - } |
|
| 2257 | - } |
|
| 2242 | + $enclosures = array(); |
|
| 2243 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2244 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2245 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2246 | + $type = extraire_attribut($e, 'type'); |
|
| 2247 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2248 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2249 | + } # vieux data |
|
| 2250 | + $fichier = basename($url); |
|
| 2251 | + $enclosures[] = '<enclosure' |
|
| 2252 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2253 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2254 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2255 | + . ' />'; |
|
| 2256 | + } |
|
| 2257 | + } |
|
| 2258 | 2258 | |
| 2259 | - return join("\n", $enclosures); |
|
| 2259 | + return join("\n", $enclosures); |
|
| 2260 | 2260 | } |
| 2261 | 2261 | |
| 2262 | 2262 | |
@@ -2272,16 +2272,16 @@ discard block |
||
| 2272 | 2272 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2273 | 2273 | **/ |
| 2274 | 2274 | function tags2dcsubject($tags) { |
| 2275 | - $subjects = ''; |
|
| 2276 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2277 | - if (extraire_attribut($e, rel) == 'tag') { |
|
| 2278 | - $subjects .= '<dc:subject>' |
|
| 2279 | - . texte_backend(textebrut($e)) |
|
| 2280 | - . '</dc:subject>' . "\n"; |
|
| 2281 | - } |
|
| 2282 | - } |
|
| 2275 | + $subjects = ''; |
|
| 2276 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2277 | + if (extraire_attribut($e, rel) == 'tag') { |
|
| 2278 | + $subjects .= '<dc:subject>' |
|
| 2279 | + . texte_backend(textebrut($e)) |
|
| 2280 | + . '</dc:subject>' . "\n"; |
|
| 2281 | + } |
|
| 2282 | + } |
|
| 2283 | 2283 | |
| 2284 | - return $subjects; |
|
| 2284 | + return $subjects; |
|
| 2285 | 2285 | } |
| 2286 | 2286 | |
| 2287 | 2287 | /** |
@@ -2310,23 +2310,23 @@ discard block |
||
| 2310 | 2310 | * - Tableau de résultats, si tableau en entrée. |
| 2311 | 2311 | **/ |
| 2312 | 2312 | function extraire_balise($texte, $tag = 'a') { |
| 2313 | - if (is_array($texte)) { |
|
| 2314 | - array_walk( |
|
| 2315 | - $texte, |
|
| 2316 | - function(&$a, $key, $t){ |
|
| 2317 | - $a = extraire_balise($a, $t); |
|
| 2318 | - }, |
|
| 2319 | - $tag |
|
| 2320 | - ); |
|
| 2313 | + if (is_array($texte)) { |
|
| 2314 | + array_walk( |
|
| 2315 | + $texte, |
|
| 2316 | + function(&$a, $key, $t){ |
|
| 2317 | + $a = extraire_balise($a, $t); |
|
| 2318 | + }, |
|
| 2319 | + $tag |
|
| 2320 | + ); |
|
| 2321 | 2321 | |
| 2322 | - return $texte; |
|
| 2323 | - } |
|
| 2322 | + return $texte; |
|
| 2323 | + } |
|
| 2324 | 2324 | |
| 2325 | - if (preg_match( |
|
| 2326 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2327 | - $texte, $regs)) { |
|
| 2328 | - return $regs[0]; |
|
| 2329 | - } |
|
| 2325 | + if (preg_match( |
|
| 2326 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2327 | + $texte, $regs)) { |
|
| 2328 | + return $regs[0]; |
|
| 2329 | + } |
|
| 2330 | 2330 | } |
| 2331 | 2331 | |
| 2332 | 2332 | /** |
@@ -2354,25 +2354,25 @@ discard block |
||
| 2354 | 2354 | * - Tableau de résultats, si tableau en entrée. |
| 2355 | 2355 | **/ |
| 2356 | 2356 | function extraire_balises($texte, $tag = 'a') { |
| 2357 | - if (is_array($texte)) { |
|
| 2358 | - array_walk( |
|
| 2359 | - $texte, |
|
| 2360 | - function(&$a, $key, $t){ |
|
| 2361 | - $a = extraire_balises($a, $t); |
|
| 2362 | - }, |
|
| 2363 | - $tag |
|
| 2364 | - ); |
|
| 2357 | + if (is_array($texte)) { |
|
| 2358 | + array_walk( |
|
| 2359 | + $texte, |
|
| 2360 | + function(&$a, $key, $t){ |
|
| 2361 | + $a = extraire_balises($a, $t); |
|
| 2362 | + }, |
|
| 2363 | + $tag |
|
| 2364 | + ); |
|
| 2365 | 2365 | |
| 2366 | - return $texte; |
|
| 2367 | - } |
|
| 2366 | + return $texte; |
|
| 2367 | + } |
|
| 2368 | 2368 | |
| 2369 | - if (preg_match_all( |
|
| 2370 | - ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2371 | - $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 2372 | - return $regs[0]; |
|
| 2373 | - } else { |
|
| 2374 | - return array(); |
|
| 2375 | - } |
|
| 2369 | + if (preg_match_all( |
|
| 2370 | + ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2371 | + $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 2372 | + return $regs[0]; |
|
| 2373 | + } else { |
|
| 2374 | + return array(); |
|
| 2375 | + } |
|
| 2376 | 2376 | } |
| 2377 | 2377 | |
| 2378 | 2378 | /** |
@@ -2401,11 +2401,11 @@ discard block |
||
| 2401 | 2401 | * - `$def` si on n'a pas transmis de tableau |
| 2402 | 2402 | **/ |
| 2403 | 2403 | function in_any($val, $vals, $def = '') { |
| 2404 | - if (!is_array($vals) and $v = unserialize($vals)) { |
|
| 2405 | - $vals = $v; |
|
| 2406 | - } |
|
| 2404 | + if (!is_array($vals) and $v = unserialize($vals)) { |
|
| 2405 | + $vals = $v; |
|
| 2406 | + } |
|
| 2407 | 2407 | |
| 2408 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2408 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2409 | 2409 | } |
| 2410 | 2410 | |
| 2411 | 2411 | |
@@ -2426,12 +2426,12 @@ discard block |
||
| 2426 | 2426 | * Résultat du calcul |
| 2427 | 2427 | **/ |
| 2428 | 2428 | function valeur_numerique($expr) { |
| 2429 | - $a = 0; |
|
| 2430 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2431 | - eval("\$a = $expr;"); |
|
| 2432 | - } |
|
| 2429 | + $a = 0; |
|
| 2430 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2431 | + eval("\$a = $expr;"); |
|
| 2432 | + } |
|
| 2433 | 2433 | |
| 2434 | - return intval($a); |
|
| 2434 | + return intval($a); |
|
| 2435 | 2435 | } |
| 2436 | 2436 | |
| 2437 | 2437 | /** |
@@ -2450,7 +2450,7 @@ discard block |
||
| 2450 | 2450 | * Retourne `$a*$b/$c` |
| 2451 | 2451 | **/ |
| 2452 | 2452 | function regledetrois($a, $b, $c) { |
| 2453 | - return round($a * $b / $c); |
|
| 2453 | + return round($a * $b / $c); |
|
| 2454 | 2454 | } |
| 2455 | 2455 | |
| 2456 | 2456 | |
@@ -2474,76 +2474,76 @@ discard block |
||
| 2474 | 2474 | **/ |
| 2475 | 2475 | function form_hidden($action) { |
| 2476 | 2476 | |
| 2477 | - $contexte = array(); |
|
| 2478 | - include_spip('inc/urls'); |
|
| 2479 | - if ($p = urls_decoder_url($action, '') |
|
| 2480 | - and reset($p) |
|
| 2481 | - ) { |
|
| 2482 | - $fond = array_shift($p); |
|
| 2483 | - if ($fond != '404') { |
|
| 2484 | - $contexte = array_shift($p); |
|
| 2485 | - $contexte['page'] = $fond; |
|
| 2486 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2487 | - } |
|
| 2488 | - } |
|
| 2489 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2490 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2491 | - unset($contexte['type']); |
|
| 2492 | - } |
|
| 2493 | - if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2494 | - unset($contexte['type-page']); |
|
| 2495 | - } |
|
| 2496 | - |
|
| 2497 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2498 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2499 | - $values = array(); |
|
| 2500 | - |
|
| 2501 | - // d'abord avec celles de l'url |
|
| 2502 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2503 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2504 | - $c = explode('=', $c, 2); |
|
| 2505 | - $var = array_shift($c); |
|
| 2506 | - $val = array_shift($c); |
|
| 2507 | - if ($var) { |
|
| 2508 | - $val = rawurldecode($val); |
|
| 2509 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2510 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2511 | - $values[] = array($var, $val); |
|
| 2512 | - } else { |
|
| 2513 | - if (!isset($values[$var])) { |
|
| 2514 | - $values[$var] = array($var, $val); |
|
| 2515 | - } |
|
| 2516 | - } |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2522 | - foreach ($contexte as $var => $val) { |
|
| 2523 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2524 | - $values[] = array($var, $val); |
|
| 2525 | - } else { |
|
| 2526 | - if (!isset($values[$var])) { |
|
| 2527 | - $values[$var] = array($var, $val); |
|
| 2528 | - } |
|
| 2529 | - } |
|
| 2530 | - } |
|
| 2531 | - |
|
| 2532 | - // puis on rassemble le tout |
|
| 2533 | - $hidden = array(); |
|
| 2534 | - foreach ($values as $value) { |
|
| 2535 | - list($var, $val) = $value; |
|
| 2536 | - $hidden[] = '<input name="' |
|
| 2537 | - . entites_html($var) |
|
| 2538 | - . '"' |
|
| 2539 | - . (is_null($val) |
|
| 2540 | - ? '' |
|
| 2541 | - : ' value="' . entites_html($val) . '"' |
|
| 2542 | - ) |
|
| 2543 | - . ' type="hidden"' . "\n/>"; |
|
| 2544 | - } |
|
| 2545 | - |
|
| 2546 | - return join("", $hidden); |
|
| 2477 | + $contexte = array(); |
|
| 2478 | + include_spip('inc/urls'); |
|
| 2479 | + if ($p = urls_decoder_url($action, '') |
|
| 2480 | + and reset($p) |
|
| 2481 | + ) { |
|
| 2482 | + $fond = array_shift($p); |
|
| 2483 | + if ($fond != '404') { |
|
| 2484 | + $contexte = array_shift($p); |
|
| 2485 | + $contexte['page'] = $fond; |
|
| 2486 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2487 | + } |
|
| 2488 | + } |
|
| 2489 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2490 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2491 | + unset($contexte['type']); |
|
| 2492 | + } |
|
| 2493 | + if (defined('_DEFINIR_CONTEXTE_TYPE_PAGE') and _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2494 | + unset($contexte['type-page']); |
|
| 2495 | + } |
|
| 2496 | + |
|
| 2497 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2498 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2499 | + $values = array(); |
|
| 2500 | + |
|
| 2501 | + // d'abord avec celles de l'url |
|
| 2502 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2503 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2504 | + $c = explode('=', $c, 2); |
|
| 2505 | + $var = array_shift($c); |
|
| 2506 | + $val = array_shift($c); |
|
| 2507 | + if ($var) { |
|
| 2508 | + $val = rawurldecode($val); |
|
| 2509 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2510 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2511 | + $values[] = array($var, $val); |
|
| 2512 | + } else { |
|
| 2513 | + if (!isset($values[$var])) { |
|
| 2514 | + $values[$var] = array($var, $val); |
|
| 2515 | + } |
|
| 2516 | + } |
|
| 2517 | + } |
|
| 2518 | + } |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2522 | + foreach ($contexte as $var => $val) { |
|
| 2523 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2524 | + $values[] = array($var, $val); |
|
| 2525 | + } else { |
|
| 2526 | + if (!isset($values[$var])) { |
|
| 2527 | + $values[$var] = array($var, $val); |
|
| 2528 | + } |
|
| 2529 | + } |
|
| 2530 | + } |
|
| 2531 | + |
|
| 2532 | + // puis on rassemble le tout |
|
| 2533 | + $hidden = array(); |
|
| 2534 | + foreach ($values as $value) { |
|
| 2535 | + list($var, $val) = $value; |
|
| 2536 | + $hidden[] = '<input name="' |
|
| 2537 | + . entites_html($var) |
|
| 2538 | + . '"' |
|
| 2539 | + . (is_null($val) |
|
| 2540 | + ? '' |
|
| 2541 | + : ' value="' . entites_html($val) . '"' |
|
| 2542 | + ) |
|
| 2543 | + . ' type="hidden"' . "\n/>"; |
|
| 2544 | + } |
|
| 2545 | + |
|
| 2546 | + return join("", $hidden); |
|
| 2547 | 2547 | } |
| 2548 | 2548 | |
| 2549 | 2549 | /** |
@@ -2561,15 +2561,15 @@ discard block |
||
| 2561 | 2561 | * Liste (première page, dernière page). |
| 2562 | 2562 | **/ |
| 2563 | 2563 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 2564 | - if ($max <= 0 or $max >= $nombre) { |
|
| 2565 | - return array(1, $nombre); |
|
| 2566 | - } |
|
| 2564 | + if ($max <= 0 or $max >= $nombre) { |
|
| 2565 | + return array(1, $nombre); |
|
| 2566 | + } |
|
| 2567 | 2567 | |
| 2568 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 2569 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 2570 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 2568 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 2569 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 2570 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 2571 | 2571 | |
| 2572 | - return array($premiere, $derniere); |
|
| 2572 | + return array($premiere, $derniere); |
|
| 2573 | 2573 | } |
| 2574 | 2574 | |
| 2575 | 2575 | |
@@ -2591,7 +2591,7 @@ discard block |
||
| 2591 | 2591 | * - la première valeur du tableau sinon. |
| 2592 | 2592 | **/ |
| 2593 | 2593 | function filtre_reset($array) { |
| 2594 | - return !is_array($array) ? null : reset($array); |
|
| 2594 | + return !is_array($array) ? null : reset($array); |
|
| 2595 | 2595 | } |
| 2596 | 2596 | |
| 2597 | 2597 | /** |
@@ -2612,7 +2612,7 @@ discard block |
||
| 2612 | 2612 | * - la dernière valeur du tableau sinon. |
| 2613 | 2613 | **/ |
| 2614 | 2614 | function filtre_end($array) { |
| 2615 | - return !is_array($array) ? null : end($array); |
|
| 2615 | + return !is_array($array) ? null : end($array); |
|
| 2616 | 2616 | } |
| 2617 | 2617 | |
| 2618 | 2618 | /** |
@@ -2632,11 +2632,11 @@ discard block |
||
| 2632 | 2632 | * |
| 2633 | 2633 | **/ |
| 2634 | 2634 | function filtre_push($array, $val) { |
| 2635 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2636 | - return ''; |
|
| 2637 | - } |
|
| 2635 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2636 | + return ''; |
|
| 2637 | + } |
|
| 2638 | 2638 | |
| 2639 | - return $array; |
|
| 2639 | + return $array; |
|
| 2640 | 2640 | } |
| 2641 | 2641 | |
| 2642 | 2642 | /** |
@@ -2655,7 +2655,7 @@ discard block |
||
| 2655 | 2655 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2656 | 2656 | **/ |
| 2657 | 2657 | function filtre_find($array, $val) { |
| 2658 | - return (is_array($array) and in_array($val, $array)); |
|
| 2658 | + return (is_array($array) and in_array($val, $array)); |
|
| 2659 | 2659 | } |
| 2660 | 2660 | |
| 2661 | 2661 | |
@@ -2690,58 +2690,58 @@ discard block |
||
| 2690 | 2690 | * Code HTML de la pagination |
| 2691 | 2691 | **/ |
| 2692 | 2692 | function filtre_pagination_dist( |
| 2693 | - $total, |
|
| 2694 | - $nom, |
|
| 2695 | - $position, |
|
| 2696 | - $pas, |
|
| 2697 | - $liste = true, |
|
| 2698 | - $modele = '', |
|
| 2699 | - $connect = '', |
|
| 2700 | - $env = array() |
|
| 2693 | + $total, |
|
| 2694 | + $nom, |
|
| 2695 | + $position, |
|
| 2696 | + $pas, |
|
| 2697 | + $liste = true, |
|
| 2698 | + $modele = '', |
|
| 2699 | + $connect = '', |
|
| 2700 | + $env = array() |
|
| 2701 | 2701 | ) { |
| 2702 | - static $ancres = array(); |
|
| 2703 | - if ($pas < 1) { |
|
| 2704 | - return ''; |
|
| 2705 | - } |
|
| 2706 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 2707 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 2708 | - |
|
| 2709 | - // n'afficher l'ancre qu'une fois |
|
| 2710 | - if (!isset($ancres[$ancre])) { |
|
| 2711 | - $bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>"; |
|
| 2712 | - } else { |
|
| 2713 | - $bloc_ancre = ''; |
|
| 2714 | - } |
|
| 2715 | - // liste = false : on ne veut que l'ancre |
|
| 2716 | - if (!$liste) { |
|
| 2717 | - return $ancres[$ancre]; |
|
| 2718 | - } |
|
| 2719 | - |
|
| 2720 | - $pagination = array( |
|
| 2721 | - 'debut' => $debut, |
|
| 2722 | - 'url' => parametre_url(self(), 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 2723 | - 'total' => $total, |
|
| 2724 | - 'position' => intval($position), |
|
| 2725 | - 'pas' => $pas, |
|
| 2726 | - 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 2727 | - 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 2728 | - 'ancre' => $ancre, |
|
| 2729 | - 'bloc_ancre' => $bloc_ancre |
|
| 2730 | - ); |
|
| 2731 | - if (is_array($env)) { |
|
| 2732 | - $pagination = array_merge($env, $pagination); |
|
| 2733 | - } |
|
| 2734 | - |
|
| 2735 | - // Pas de pagination |
|
| 2736 | - if ($pagination['nombre_pages'] <= 1) { |
|
| 2737 | - return ''; |
|
| 2738 | - } |
|
| 2739 | - |
|
| 2740 | - if ($modele) { |
|
| 2741 | - $modele = '_' . $modele; |
|
| 2742 | - } |
|
| 2743 | - |
|
| 2744 | - return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect); |
|
| 2702 | + static $ancres = array(); |
|
| 2703 | + if ($pas < 1) { |
|
| 2704 | + return ''; |
|
| 2705 | + } |
|
| 2706 | + $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 2707 | + $debut = 'debut' . $nom; // 'debut_articles' |
|
| 2708 | + |
|
| 2709 | + // n'afficher l'ancre qu'une fois |
|
| 2710 | + if (!isset($ancres[$ancre])) { |
|
| 2711 | + $bloc_ancre = $ancres[$ancre] = "<a name='" . $ancre . "' id='" . $ancre . "'></a>"; |
|
| 2712 | + } else { |
|
| 2713 | + $bloc_ancre = ''; |
|
| 2714 | + } |
|
| 2715 | + // liste = false : on ne veut que l'ancre |
|
| 2716 | + if (!$liste) { |
|
| 2717 | + return $ancres[$ancre]; |
|
| 2718 | + } |
|
| 2719 | + |
|
| 2720 | + $pagination = array( |
|
| 2721 | + 'debut' => $debut, |
|
| 2722 | + 'url' => parametre_url(self(), 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 2723 | + 'total' => $total, |
|
| 2724 | + 'position' => intval($position), |
|
| 2725 | + 'pas' => $pas, |
|
| 2726 | + 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 2727 | + 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 2728 | + 'ancre' => $ancre, |
|
| 2729 | + 'bloc_ancre' => $bloc_ancre |
|
| 2730 | + ); |
|
| 2731 | + if (is_array($env)) { |
|
| 2732 | + $pagination = array_merge($env, $pagination); |
|
| 2733 | + } |
|
| 2734 | + |
|
| 2735 | + // Pas de pagination |
|
| 2736 | + if ($pagination['nombre_pages'] <= 1) { |
|
| 2737 | + return ''; |
|
| 2738 | + } |
|
| 2739 | + |
|
| 2740 | + if ($modele) { |
|
| 2741 | + $modele = '_' . $modele; |
|
| 2742 | + } |
|
| 2743 | + |
|
| 2744 | + return recuperer_fond("modeles/pagination$modele", $pagination, array('trim' => true), $connect); |
|
| 2745 | 2745 | } |
| 2746 | 2746 | |
| 2747 | 2747 | |
@@ -2758,15 +2758,15 @@ discard block |
||
| 2758 | 2758 | * Contenu avec urls en absolus |
| 2759 | 2759 | **/ |
| 2760 | 2760 | function urls_absolues_css($contenu, $source) { |
| 2761 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2761 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2762 | 2762 | |
| 2763 | - return preg_replace_callback( |
|
| 2764 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2765 | - function($x) use ($path) { |
|
| 2766 | - return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2767 | - }, |
|
| 2768 | - $contenu |
|
| 2769 | - ); |
|
| 2763 | + return preg_replace_callback( |
|
| 2764 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2765 | + function($x) use ($path) { |
|
| 2766 | + return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2767 | + }, |
|
| 2768 | + $contenu |
|
| 2769 | + ); |
|
| 2770 | 2770 | } |
| 2771 | 2771 | |
| 2772 | 2772 | |
@@ -2795,118 +2795,118 @@ discard block |
||
| 2795 | 2795 | * Chemin du fichier CSS inversé |
| 2796 | 2796 | **/ |
| 2797 | 2797 | function direction_css($css, $voulue = '') { |
| 2798 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2799 | - return $css; |
|
| 2800 | - } |
|
| 2801 | - |
|
| 2802 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2803 | - if ($voulue = strtolower($voulue)) { |
|
| 2804 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2805 | - $voulue = lang_dir($voulue); |
|
| 2806 | - } |
|
| 2807 | - } else { |
|
| 2808 | - $voulue = lang_dir(); |
|
| 2809 | - } |
|
| 2810 | - |
|
| 2811 | - $r = count($r) > 1; |
|
| 2812 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2813 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2814 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2815 | - |
|
| 2816 | - if ($voulue == $dir) { |
|
| 2817 | - return $css; |
|
| 2818 | - } |
|
| 2819 | - |
|
| 2820 | - if ( |
|
| 2821 | - // url absolue |
|
| 2822 | - preg_match(",^https?:,i", $css) |
|
| 2823 | - // ou qui contient un ? |
|
| 2824 | - or (($p = strpos($css, '?')) !== false) |
|
| 2825 | - ) { |
|
| 2826 | - $distant = true; |
|
| 2827 | - $cssf = parse_url($css); |
|
| 2828 | - $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : ""); |
|
| 2829 | - $cssf = preg_replace(',[?:&=],', "_", $cssf); |
|
| 2830 | - } else { |
|
| 2831 | - $distant = false; |
|
| 2832 | - $cssf = $css; |
|
| 2833 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2834 | - //propose (rien a faire dans ce cas) |
|
| 2835 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2836 | - if (@file_exists($f)) { |
|
| 2837 | - return $f; |
|
| 2838 | - } |
|
| 2839 | - } |
|
| 2840 | - |
|
| 2841 | - // 2. |
|
| 2842 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2843 | - $f = $dir_var |
|
| 2844 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2845 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2846 | - |
|
| 2847 | - // la css peut etre distante (url absolue !) |
|
| 2848 | - if ($distant) { |
|
| 2849 | - include_spip('inc/distant'); |
|
| 2850 | - $res = recuperer_url($css); |
|
| 2851 | - if (!$res or !$contenu = $res['page']) { |
|
| 2852 | - return $css; |
|
| 2853 | - } |
|
| 2854 | - } else { |
|
| 2855 | - if ((@filemtime($f) > @filemtime($css)) |
|
| 2856 | - and (_VAR_MODE != 'recalcul') |
|
| 2857 | - ) { |
|
| 2858 | - return $f; |
|
| 2859 | - } |
|
| 2860 | - if (!lire_fichier($css, $contenu)) { |
|
| 2861 | - return $css; |
|
| 2862 | - } |
|
| 2863 | - } |
|
| 2864 | - |
|
| 2865 | - |
|
| 2866 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2867 | - include_spip("lib/csstidy/class.csstidy"); |
|
| 2868 | - $parser = new csstidy(); |
|
| 2869 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 2870 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 2871 | - $parser->parse($contenu); |
|
| 2872 | - |
|
| 2873 | - $contenu = $parser->print->plain(); |
|
| 2874 | - |
|
| 2875 | - |
|
| 2876 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2877 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2878 | - $src = array(); |
|
| 2879 | - $src_direction_css = array(); |
|
| 2880 | - $src_faux_abs = array(); |
|
| 2881 | - $d = dirname($css); |
|
| 2882 | - foreach ($regs[1] as $k => $import_css) { |
|
| 2883 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2884 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2885 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2886 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2887 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2888 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2889 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2890 | - $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction; |
|
| 2891 | - $css_direction = "/@@@@@@/" . $css_direction; |
|
| 2892 | - } |
|
| 2893 | - $src[] = $regs[0][$k]; |
|
| 2894 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2895 | - } |
|
| 2896 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2897 | - |
|
| 2898 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2899 | - |
|
| 2900 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 2901 | - if (count($src_faux_abs)) { |
|
| 2902 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2903 | - } |
|
| 2904 | - |
|
| 2905 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 2906 | - return $css; |
|
| 2907 | - } |
|
| 2908 | - |
|
| 2909 | - return $f; |
|
| 2798 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2799 | + return $css; |
|
| 2800 | + } |
|
| 2801 | + |
|
| 2802 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2803 | + if ($voulue = strtolower($voulue)) { |
|
| 2804 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2805 | + $voulue = lang_dir($voulue); |
|
| 2806 | + } |
|
| 2807 | + } else { |
|
| 2808 | + $voulue = lang_dir(); |
|
| 2809 | + } |
|
| 2810 | + |
|
| 2811 | + $r = count($r) > 1; |
|
| 2812 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2813 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2814 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2815 | + |
|
| 2816 | + if ($voulue == $dir) { |
|
| 2817 | + return $css; |
|
| 2818 | + } |
|
| 2819 | + |
|
| 2820 | + if ( |
|
| 2821 | + // url absolue |
|
| 2822 | + preg_match(",^https?:,i", $css) |
|
| 2823 | + // ou qui contient un ? |
|
| 2824 | + or (($p = strpos($css, '?')) !== false) |
|
| 2825 | + ) { |
|
| 2826 | + $distant = true; |
|
| 2827 | + $cssf = parse_url($css); |
|
| 2828 | + $cssf = $cssf['path'] . ($cssf['query'] ? "?" . $cssf['query'] : ""); |
|
| 2829 | + $cssf = preg_replace(',[?:&=],', "_", $cssf); |
|
| 2830 | + } else { |
|
| 2831 | + $distant = false; |
|
| 2832 | + $cssf = $css; |
|
| 2833 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2834 | + //propose (rien a faire dans ce cas) |
|
| 2835 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2836 | + if (@file_exists($f)) { |
|
| 2837 | + return $f; |
|
| 2838 | + } |
|
| 2839 | + } |
|
| 2840 | + |
|
| 2841 | + // 2. |
|
| 2842 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2843 | + $f = $dir_var |
|
| 2844 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2845 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2846 | + |
|
| 2847 | + // la css peut etre distante (url absolue !) |
|
| 2848 | + if ($distant) { |
|
| 2849 | + include_spip('inc/distant'); |
|
| 2850 | + $res = recuperer_url($css); |
|
| 2851 | + if (!$res or !$contenu = $res['page']) { |
|
| 2852 | + return $css; |
|
| 2853 | + } |
|
| 2854 | + } else { |
|
| 2855 | + if ((@filemtime($f) > @filemtime($css)) |
|
| 2856 | + and (_VAR_MODE != 'recalcul') |
|
| 2857 | + ) { |
|
| 2858 | + return $f; |
|
| 2859 | + } |
|
| 2860 | + if (!lire_fichier($css, $contenu)) { |
|
| 2861 | + return $css; |
|
| 2862 | + } |
|
| 2863 | + } |
|
| 2864 | + |
|
| 2865 | + |
|
| 2866 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2867 | + include_spip("lib/csstidy/class.csstidy"); |
|
| 2868 | + $parser = new csstidy(); |
|
| 2869 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 2870 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 2871 | + $parser->parse($contenu); |
|
| 2872 | + |
|
| 2873 | + $contenu = $parser->print->plain(); |
|
| 2874 | + |
|
| 2875 | + |
|
| 2876 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2877 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2878 | + $src = array(); |
|
| 2879 | + $src_direction_css = array(); |
|
| 2880 | + $src_faux_abs = array(); |
|
| 2881 | + $d = dirname($css); |
|
| 2882 | + foreach ($regs[1] as $k => $import_css) { |
|
| 2883 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2884 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2885 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2886 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2887 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2888 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2889 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2890 | + $src_faux_abs["/@@@@@@/" . $css_direction] = $css_direction; |
|
| 2891 | + $css_direction = "/@@@@@@/" . $css_direction; |
|
| 2892 | + } |
|
| 2893 | + $src[] = $regs[0][$k]; |
|
| 2894 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2895 | + } |
|
| 2896 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2897 | + |
|
| 2898 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2899 | + |
|
| 2900 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 2901 | + if (count($src_faux_abs)) { |
|
| 2902 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 2903 | + } |
|
| 2904 | + |
|
| 2905 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 2906 | + return $css; |
|
| 2907 | + } |
|
| 2908 | + |
|
| 2909 | + return $f; |
|
| 2910 | 2910 | } |
| 2911 | 2911 | |
| 2912 | 2912 | |
@@ -2929,43 +2929,43 @@ discard block |
||
| 2929 | 2929 | * - Chemin ou URL du fichier CSS source sinon. |
| 2930 | 2930 | **/ |
| 2931 | 2931 | function url_absolue_css($css) { |
| 2932 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 2933 | - return $css; |
|
| 2934 | - } |
|
| 2932 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 2933 | + return $css; |
|
| 2934 | + } |
|
| 2935 | 2935 | |
| 2936 | - $url_absolue_css = url_absolue($css); |
|
| 2936 | + $url_absolue_css = url_absolue($css); |
|
| 2937 | 2937 | |
| 2938 | - $f = basename($css, '.css'); |
|
| 2939 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 2940 | - . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 2941 | - . '.css'; |
|
| 2938 | + $f = basename($css, '.css'); |
|
| 2939 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 2940 | + . preg_replace(",(.*?)(_rtl|_ltr)?$,", "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 2941 | + . '.css'; |
|
| 2942 | 2942 | |
| 2943 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 2944 | - return $f; |
|
| 2945 | - } |
|
| 2943 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 2944 | + return $f; |
|
| 2945 | + } |
|
| 2946 | 2946 | |
| 2947 | - if ($url_absolue_css == $css) { |
|
| 2948 | - if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 2949 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 2950 | - ) { |
|
| 2951 | - include_spip('inc/distant'); |
|
| 2952 | - if (!$contenu = recuperer_page($css)) { |
|
| 2953 | - return $css; |
|
| 2954 | - } |
|
| 2955 | - } |
|
| 2956 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 2957 | - return $css; |
|
| 2958 | - } |
|
| 2947 | + if ($url_absolue_css == $css) { |
|
| 2948 | + if (strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 2949 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 2950 | + ) { |
|
| 2951 | + include_spip('inc/distant'); |
|
| 2952 | + if (!$contenu = recuperer_page($css)) { |
|
| 2953 | + return $css; |
|
| 2954 | + } |
|
| 2955 | + } |
|
| 2956 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 2957 | + return $css; |
|
| 2958 | + } |
|
| 2959 | 2959 | |
| 2960 | - // passer les url relatives a la css d'origine en url absolues |
|
| 2961 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2960 | + // passer les url relatives a la css d'origine en url absolues |
|
| 2961 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2962 | 2962 | |
| 2963 | - // ecrire la css |
|
| 2964 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 2965 | - return $css; |
|
| 2966 | - } |
|
| 2963 | + // ecrire la css |
|
| 2964 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 2965 | + return $css; |
|
| 2966 | + } |
|
| 2967 | 2967 | |
| 2968 | - return $f; |
|
| 2968 | + return $f; |
|
| 2969 | 2969 | } |
| 2970 | 2970 | |
| 2971 | 2971 | |
@@ -2999,24 +2999,24 @@ discard block |
||
| 2999 | 2999 | * Valeur trouvée ou valeur par défaut. |
| 3000 | 3000 | **/ |
| 3001 | 3001 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3002 | - foreach (explode('/', $cle) as $k) { |
|
| 3002 | + foreach (explode('/', $cle) as $k) { |
|
| 3003 | 3003 | |
| 3004 | - $table = is_string($table) ? @unserialize($table) : $table; |
|
| 3004 | + $table = is_string($table) ? @unserialize($table) : $table; |
|
| 3005 | 3005 | |
| 3006 | - if (is_object($table)) { |
|
| 3007 | - $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3008 | - } elseif (is_array($table)) { |
|
| 3009 | - if ($conserver_null) { |
|
| 3010 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3011 | - } else { |
|
| 3012 | - $table = isset($table[$k]) ? $table[$k] : $defaut; |
|
| 3013 | - } |
|
| 3014 | - } else { |
|
| 3015 | - $table = $defaut; |
|
| 3016 | - } |
|
| 3017 | - } |
|
| 3006 | + if (is_object($table)) { |
|
| 3007 | + $table = (($k !== "") and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3008 | + } elseif (is_array($table)) { |
|
| 3009 | + if ($conserver_null) { |
|
| 3010 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3011 | + } else { |
|
| 3012 | + $table = isset($table[$k]) ? $table[$k] : $defaut; |
|
| 3013 | + } |
|
| 3014 | + } else { |
|
| 3015 | + $table = $defaut; |
|
| 3016 | + } |
|
| 3017 | + } |
|
| 3018 | 3018 | |
| 3019 | - return $table; |
|
| 3019 | + return $table; |
|
| 3020 | 3020 | } |
| 3021 | 3021 | |
| 3022 | 3022 | /** |
@@ -3049,22 +3049,22 @@ discard block |
||
| 3049 | 3049 | * - string : expression trouvée. |
| 3050 | 3050 | **/ |
| 3051 | 3051 | function match($texte, $expression, $modif = "UimsS", $capte = 0) { |
| 3052 | - if (intval($modif) and $capte == 0) { |
|
| 3053 | - $capte = $modif; |
|
| 3054 | - $modif = "UimsS"; |
|
| 3055 | - } |
|
| 3056 | - $expression = str_replace("\/", "/", $expression); |
|
| 3057 | - $expression = str_replace("/", "\/", $expression); |
|
| 3052 | + if (intval($modif) and $capte == 0) { |
|
| 3053 | + $capte = $modif; |
|
| 3054 | + $modif = "UimsS"; |
|
| 3055 | + } |
|
| 3056 | + $expression = str_replace("\/", "/", $expression); |
|
| 3057 | + $expression = str_replace("/", "\/", $expression); |
|
| 3058 | 3058 | |
| 3059 | - if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3060 | - if (isset($r[$capte])) { |
|
| 3061 | - return $r[$capte]; |
|
| 3062 | - } else { |
|
| 3063 | - return true; |
|
| 3064 | - } |
|
| 3065 | - } |
|
| 3059 | + if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3060 | + if (isset($r[$capte])) { |
|
| 3061 | + return $r[$capte]; |
|
| 3062 | + } else { |
|
| 3063 | + return true; |
|
| 3064 | + } |
|
| 3065 | + } |
|
| 3066 | 3066 | |
| 3067 | - return false; |
|
| 3067 | + return false; |
|
| 3068 | 3068 | } |
| 3069 | 3069 | |
| 3070 | 3070 | |
@@ -3091,10 +3091,10 @@ discard block |
||
| 3091 | 3091 | * Texte |
| 3092 | 3092 | **/ |
| 3093 | 3093 | function replace($texte, $expression, $replace = '', $modif = "UimsS") { |
| 3094 | - $expression = str_replace("\/", "/", $expression); |
|
| 3095 | - $expression = str_replace("/", "\/", $expression); |
|
| 3094 | + $expression = str_replace("\/", "/", $expression); |
|
| 3095 | + $expression = str_replace("/", "\/", $expression); |
|
| 3096 | 3096 | |
| 3097 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3097 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3098 | 3098 | } |
| 3099 | 3099 | |
| 3100 | 3100 | |
@@ -3112,21 +3112,21 @@ discard block |
||
| 3112 | 3112 | **/ |
| 3113 | 3113 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3114 | 3114 | |
| 3115 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3116 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3115 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3116 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3117 | 3117 | |
| 3118 | - if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3119 | - and preg_match_all( |
|
| 3120 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3121 | - $t, $matches, PREG_PATTERN_ORDER) |
|
| 3122 | - ) { |
|
| 3123 | - if (!isset($doublons['documents'])) { |
|
| 3124 | - $doublons['documents'] = ""; |
|
| 3125 | - } |
|
| 3126 | - $doublons['documents'] .= "," . join(',', $matches[1]); |
|
| 3127 | - } |
|
| 3118 | + if (strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3119 | + and preg_match_all( |
|
| 3120 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3121 | + $t, $matches, PREG_PATTERN_ORDER) |
|
| 3122 | + ) { |
|
| 3123 | + if (!isset($doublons['documents'])) { |
|
| 3124 | + $doublons['documents'] = ""; |
|
| 3125 | + } |
|
| 3126 | + $doublons['documents'] .= "," . join(',', $matches[1]); |
|
| 3127 | + } |
|
| 3128 | 3128 | |
| 3129 | - return $letexte; |
|
| 3129 | + return $letexte; |
|
| 3130 | 3130 | } |
| 3131 | 3131 | |
| 3132 | 3132 | /** |
@@ -3140,7 +3140,7 @@ discard block |
||
| 3140 | 3140 | * @return string Chaîne vide |
| 3141 | 3141 | **/ |
| 3142 | 3142 | function vide($texte) { |
| 3143 | - return ""; |
|
| 3143 | + return ""; |
|
| 3144 | 3144 | } |
| 3145 | 3145 | |
| 3146 | 3146 | // |
@@ -3169,23 +3169,23 @@ discard block |
||
| 3169 | 3169 | * Code HTML résultant |
| 3170 | 3170 | **/ |
| 3171 | 3171 | function env_to_params($env, $ignore_params = array()) { |
| 3172 | - $ignore_params = array_merge( |
|
| 3173 | - array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3174 | - $ignore_params |
|
| 3175 | - ); |
|
| 3176 | - if (!is_array($env)) { |
|
| 3177 | - $env = unserialize($env); |
|
| 3178 | - } |
|
| 3179 | - $texte = ""; |
|
| 3180 | - if ($env) { |
|
| 3181 | - foreach ($env as $i => $j) { |
|
| 3182 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3183 | - $texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />"; |
|
| 3184 | - } |
|
| 3185 | - } |
|
| 3186 | - } |
|
| 3187 | - |
|
| 3188 | - return $texte; |
|
| 3172 | + $ignore_params = array_merge( |
|
| 3173 | + array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3174 | + $ignore_params |
|
| 3175 | + ); |
|
| 3176 | + if (!is_array($env)) { |
|
| 3177 | + $env = unserialize($env); |
|
| 3178 | + } |
|
| 3179 | + $texte = ""; |
|
| 3180 | + if ($env) { |
|
| 3181 | + foreach ($env as $i => $j) { |
|
| 3182 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3183 | + $texte .= "<param name='" . $i . "'\n\tvalue='" . $j . "' />"; |
|
| 3184 | + } |
|
| 3185 | + } |
|
| 3186 | + } |
|
| 3187 | + |
|
| 3188 | + return $texte; |
|
| 3189 | 3189 | } |
| 3190 | 3190 | |
| 3191 | 3191 | /** |
@@ -3208,23 +3208,23 @@ discard block |
||
| 3208 | 3208 | * Code HTML résultant |
| 3209 | 3209 | **/ |
| 3210 | 3210 | function env_to_attributs($env, $ignore_params = array()) { |
| 3211 | - $ignore_params = array_merge( |
|
| 3212 | - array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3213 | - $ignore_params |
|
| 3214 | - ); |
|
| 3215 | - if (!is_array($env)) { |
|
| 3216 | - $env = unserialize($env); |
|
| 3217 | - } |
|
| 3218 | - $texte = ""; |
|
| 3219 | - if ($env) { |
|
| 3220 | - foreach ($env as $i => $j) { |
|
| 3221 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3222 | - $texte .= $i . "='" . $j . "' "; |
|
| 3223 | - } |
|
| 3224 | - } |
|
| 3225 | - } |
|
| 3211 | + $ignore_params = array_merge( |
|
| 3212 | + array('id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'), |
|
| 3213 | + $ignore_params |
|
| 3214 | + ); |
|
| 3215 | + if (!is_array($env)) { |
|
| 3216 | + $env = unserialize($env); |
|
| 3217 | + } |
|
| 3218 | + $texte = ""; |
|
| 3219 | + if ($env) { |
|
| 3220 | + foreach ($env as $i => $j) { |
|
| 3221 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3222 | + $texte .= $i . "='" . $j . "' "; |
|
| 3223 | + } |
|
| 3224 | + } |
|
| 3225 | + } |
|
| 3226 | 3226 | |
| 3227 | - return $texte; |
|
| 3227 | + return $texte; |
|
| 3228 | 3228 | } |
| 3229 | 3229 | |
| 3230 | 3230 | |
@@ -3241,9 +3241,9 @@ discard block |
||
| 3241 | 3241 | * @return string Chaînes concaténés |
| 3242 | 3242 | **/ |
| 3243 | 3243 | function concat() { |
| 3244 | - $args = func_get_args(); |
|
| 3244 | + $args = func_get_args(); |
|
| 3245 | 3245 | |
| 3246 | - return join('', $args); |
|
| 3246 | + return join('', $args); |
|
| 3247 | 3247 | } |
| 3248 | 3248 | |
| 3249 | 3249 | |
@@ -3263,23 +3263,23 @@ discard block |
||
| 3263 | 3263 | * Contenu du ou des fichiers, concaténé |
| 3264 | 3264 | **/ |
| 3265 | 3265 | function charge_scripts($files, $script = true) { |
| 3266 | - $flux = ""; |
|
| 3267 | - foreach (is_array($files) ? $files : explode("|", $files) as $file) { |
|
| 3268 | - if (!is_string($file)) { |
|
| 3269 | - continue; |
|
| 3270 | - } |
|
| 3271 | - if ($script) { |
|
| 3272 | - $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : ''; |
|
| 3273 | - } |
|
| 3274 | - if ($file) { |
|
| 3275 | - $path = find_in_path($file); |
|
| 3276 | - if ($path) { |
|
| 3277 | - $flux .= spip_file_get_contents($path); |
|
| 3278 | - } |
|
| 3279 | - } |
|
| 3280 | - } |
|
| 3266 | + $flux = ""; |
|
| 3267 | + foreach (is_array($files) ? $files : explode("|", $files) as $file) { |
|
| 3268 | + if (!is_string($file)) { |
|
| 3269 | + continue; |
|
| 3270 | + } |
|
| 3271 | + if ($script) { |
|
| 3272 | + $file = preg_match(",^\w+$,", $file) ? "javascript/$file.js" : ''; |
|
| 3273 | + } |
|
| 3274 | + if ($file) { |
|
| 3275 | + $path = find_in_path($file); |
|
| 3276 | + if ($path) { |
|
| 3277 | + $flux .= spip_file_get_contents($path); |
|
| 3278 | + } |
|
| 3279 | + } |
|
| 3280 | + } |
|
| 3281 | 3281 | |
| 3282 | - return $flux; |
|
| 3282 | + return $flux; |
|
| 3283 | 3283 | } |
| 3284 | 3284 | |
| 3285 | 3285 | |
@@ -3299,29 +3299,29 @@ discard block |
||
| 3299 | 3299 | * @return string |
| 3300 | 3300 | */ |
| 3301 | 3301 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = array()) { |
| 3302 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3303 | - $img = chemin_image($img); |
|
| 3304 | - } |
|
| 3305 | - if (stripos($atts, 'width') === false) { |
|
| 3306 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3307 | - if ((!isset($options['utiliser_suffixe_size']) or $options['utiliser_suffixe_size'] == true) |
|
| 3308 | - and preg_match(',-([0-9]+)[.](png|gif)$,', $img, $regs) |
|
| 3309 | - ) { |
|
| 3310 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3311 | - } else { |
|
| 3312 | - $taille = taille_image($img); |
|
| 3313 | - list($hauteur, $largeur) = $taille; |
|
| 3314 | - if (!$hauteur or !$largeur) { |
|
| 3315 | - return ""; |
|
| 3316 | - } |
|
| 3317 | - } |
|
| 3318 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3319 | - } |
|
| 3320 | - |
|
| 3321 | - return "<img src='$img' alt='" . attribut_html($alt ? $alt : $title) . "'" |
|
| 3322 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3323 | - . " " . ltrim($atts) |
|
| 3324 | - . " />"; |
|
| 3302 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3303 | + $img = chemin_image($img); |
|
| 3304 | + } |
|
| 3305 | + if (stripos($atts, 'width') === false) { |
|
| 3306 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3307 | + if ((!isset($options['utiliser_suffixe_size']) or $options['utiliser_suffixe_size'] == true) |
|
| 3308 | + and preg_match(',-([0-9]+)[.](png|gif)$,', $img, $regs) |
|
| 3309 | + ) { |
|
| 3310 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3311 | + } else { |
|
| 3312 | + $taille = taille_image($img); |
|
| 3313 | + list($hauteur, $largeur) = $taille; |
|
| 3314 | + if (!$hauteur or !$largeur) { |
|
| 3315 | + return ""; |
|
| 3316 | + } |
|
| 3317 | + } |
|
| 3318 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3319 | + } |
|
| 3320 | + |
|
| 3321 | + return "<img src='$img' alt='" . attribut_html($alt ? $alt : $title) . "'" |
|
| 3322 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3323 | + . " " . ltrim($atts) |
|
| 3324 | + . " />"; |
|
| 3325 | 3325 | } |
| 3326 | 3326 | |
| 3327 | 3327 | /** |
@@ -3332,7 +3332,7 @@ discard block |
||
| 3332 | 3332 | * @return string |
| 3333 | 3333 | */ |
| 3334 | 3334 | function http_style_background($img, $att = '') { |
| 3335 | - return " style='background" . ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";'"; |
|
| 3335 | + return " style='background" . ($att ? "" : "-image") . ": url(\"" . chemin_image($img) . "\")" . ($att ? (' ' . $att) : '') . ";'"; |
|
| 3336 | 3336 | } |
| 3337 | 3337 | |
| 3338 | 3338 | /** |
@@ -3347,8 +3347,8 @@ discard block |
||
| 3347 | 3347 | * Code HTML de la balise IMG |
| 3348 | 3348 | */ |
| 3349 | 3349 | function filtre_balise_img_dist($img, $alt = "", $class = "") { |
| 3350 | - return http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '', |
|
| 3351 | - array('chemin_image' => false, 'utiliser_suffixe_size' => false)); |
|
| 3350 | + return http_img_pack($img, $alt, $class ? " class='" . attribut_html($class) . "'" : '', '', |
|
| 3351 | + array('chemin_image' => false, 'utiliser_suffixe_size' => false)); |
|
| 3352 | 3352 | } |
| 3353 | 3353 | |
| 3354 | 3354 | |
@@ -3370,17 +3370,17 @@ discard block |
||
| 3370 | 3370 | * Code HTML résultant |
| 3371 | 3371 | **/ |
| 3372 | 3372 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3373 | - $texte = ''; |
|
| 3374 | - if (is_array($tableau)) { |
|
| 3375 | - foreach ($tableau as $k => $v) { |
|
| 3376 | - $res = recuperer_fond('modeles/' . $modele, |
|
| 3377 | - array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v))) |
|
| 3378 | - ); |
|
| 3379 | - $texte .= $res; |
|
| 3380 | - } |
|
| 3381 | - } |
|
| 3373 | + $texte = ''; |
|
| 3374 | + if (is_array($tableau)) { |
|
| 3375 | + foreach ($tableau as $k => $v) { |
|
| 3376 | + $res = recuperer_fond('modeles/' . $modele, |
|
| 3377 | + array_merge(array('cle' => $k), (is_array($v) ? $v : array('valeur' => $v))) |
|
| 3378 | + ); |
|
| 3379 | + $texte .= $res; |
|
| 3380 | + } |
|
| 3381 | + } |
|
| 3382 | 3382 | |
| 3383 | - return $texte; |
|
| 3383 | + return $texte; |
|
| 3384 | 3384 | } |
| 3385 | 3385 | |
| 3386 | 3386 | |
@@ -3405,37 +3405,37 @@ discard block |
||
| 3405 | 3405 | * - tout : retourne toutes les informations du plugin actif |
| 3406 | 3406 | **/ |
| 3407 | 3407 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3408 | - include_spip('inc/plugin'); |
|
| 3409 | - $plugin = strtoupper($plugin); |
|
| 3410 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3411 | - |
|
| 3412 | - if (!$plugin) { |
|
| 3413 | - return serialize(array_keys($plugins_actifs)); |
|
| 3414 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3415 | - return ''; |
|
| 3416 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3417 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3418 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3419 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3420 | - } else { |
|
| 3421 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3422 | - // On prend en compte les extensions |
|
| 3423 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3424 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3425 | - } else { |
|
| 3426 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3427 | - } |
|
| 3428 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3429 | - return ''; |
|
| 3430 | - } |
|
| 3431 | - if ($type_info == 'tout') { |
|
| 3432 | - return $infos; |
|
| 3433 | - } elseif ($type_info == 'est_actif') { |
|
| 3434 | - return $infos ? 1 : 0; |
|
| 3435 | - } else { |
|
| 3436 | - return strval($infos[$type_info]); |
|
| 3437 | - } |
|
| 3438 | - } |
|
| 3408 | + include_spip('inc/plugin'); |
|
| 3409 | + $plugin = strtoupper($plugin); |
|
| 3410 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3411 | + |
|
| 3412 | + if (!$plugin) { |
|
| 3413 | + return serialize(array_keys($plugins_actifs)); |
|
| 3414 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3415 | + return ''; |
|
| 3416 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3417 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3418 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3419 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3420 | + } else { |
|
| 3421 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3422 | + // On prend en compte les extensions |
|
| 3423 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3424 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3425 | + } else { |
|
| 3426 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3427 | + } |
|
| 3428 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3429 | + return ''; |
|
| 3430 | + } |
|
| 3431 | + if ($type_info == 'tout') { |
|
| 3432 | + return $infos; |
|
| 3433 | + } elseif ($type_info == 'est_actif') { |
|
| 3434 | + return $infos ? 1 : 0; |
|
| 3435 | + } else { |
|
| 3436 | + return strval($infos[$type_info]); |
|
| 3437 | + } |
|
| 3438 | + } |
|
| 3439 | 3439 | } |
| 3440 | 3440 | |
| 3441 | 3441 | |
@@ -3462,9 +3462,9 @@ discard block |
||
| 3462 | 3462 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3463 | 3463 | */ |
| 3464 | 3464 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3465 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3465 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3466 | 3466 | |
| 3467 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3467 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3468 | 3468 | } |
| 3469 | 3469 | |
| 3470 | 3470 | |
@@ -3494,13 +3494,13 @@ discard block |
||
| 3494 | 3494 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3495 | 3495 | */ |
| 3496 | 3496 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3497 | - static $puce_statut = null; |
|
| 3498 | - if (!$puce_statut) { |
|
| 3499 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3500 | - } |
|
| 3497 | + static $puce_statut = null; |
|
| 3498 | + if (!$puce_statut) { |
|
| 3499 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3500 | + } |
|
| 3501 | 3501 | |
| 3502 | - return $puce_statut($id_objet, $statut, $id_parent, $objet, false, |
|
| 3503 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false); |
|
| 3502 | + return $puce_statut($id_objet, $statut, $id_parent, $objet, false, |
|
| 3503 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false); |
|
| 3504 | 3504 | } |
| 3505 | 3505 | |
| 3506 | 3506 | |
@@ -3527,88 +3527,88 @@ discard block |
||
| 3527 | 3527 | * hash du contexte |
| 3528 | 3528 | */ |
| 3529 | 3529 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3530 | - if (is_string($c) |
|
| 3531 | - and @unserialize($c) !== false |
|
| 3532 | - ) { |
|
| 3533 | - $c = unserialize($c); |
|
| 3534 | - } |
|
| 3535 | - |
|
| 3536 | - // supprimer les parametres debut_x |
|
| 3537 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3538 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3539 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3540 | - if (is_array($c)) { |
|
| 3541 | - foreach ($c as $k => $v) { |
|
| 3542 | - if (strpos($k, 'debut_') === 0) { |
|
| 3543 | - unset($c[$k]); |
|
| 3544 | - } |
|
| 3545 | - } |
|
| 3546 | - } |
|
| 3547 | - |
|
| 3548 | - if (!function_exists('calculer_cle_action')) { |
|
| 3549 | - include_spip("inc/securiser_action"); |
|
| 3550 | - } |
|
| 3551 | - |
|
| 3552 | - $c = serialize($c); |
|
| 3553 | - $cle = calculer_cle_action($form . $c); |
|
| 3554 | - $c = "$cle:$c"; |
|
| 3555 | - |
|
| 3556 | - // on ne stocke pas les contextes dans des fichiers caches |
|
| 3557 | - // par defaut, sauf si cette configuration a ete forcee |
|
| 3558 | - // OU que la longueur de l''argument generee est plus long |
|
| 3559 | - // que ce que telere Suhosin. |
|
| 3560 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3561 | - if (!$cache_contextes_ajax) { |
|
| 3562 | - $env = $c; |
|
| 3563 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3564 | - $env = gzdeflate($env); |
|
| 3565 | - // http://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287 |
|
| 3566 | - if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) { |
|
| 3567 | - $cache_contextes_ajax = true; |
|
| 3568 | - spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT); |
|
| 3569 | - } |
|
| 3570 | - } |
|
| 3571 | - $env = _xor($env); |
|
| 3572 | - $env = base64_encode($env); |
|
| 3573 | - // tester Suhosin et la valeur maximale des variables en GET... |
|
| 3574 | - if ($max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3575 | - and $max_len < ($len = strlen($env)) |
|
| 3576 | - ) { |
|
| 3577 | - $cache_contextes_ajax = true; |
|
| 3578 | - spip_log("Contextes AJAX forces en fichiers !" |
|
| 3579 | - . " Cela arrive lorsque la valeur du contexte" |
|
| 3580 | - . " depasse la longueur maximale autorisee par Suhosin" |
|
| 3581 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3582 | - . " Vous devriez modifier les parametres de Suhosin" |
|
| 3583 | - . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT); |
|
| 3584 | - } |
|
| 3585 | - } |
|
| 3586 | - |
|
| 3587 | - if ($cache_contextes_ajax) { |
|
| 3588 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3589 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3590 | - $md5 = md5($c); |
|
| 3591 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 3592 | - $env = $md5; |
|
| 3593 | - } |
|
| 3594 | - |
|
| 3595 | - if ($emboite === null) { |
|
| 3596 | - return $env; |
|
| 3597 | - } |
|
| 3598 | - if (!trim($emboite)) { |
|
| 3599 | - return ""; |
|
| 3600 | - } |
|
| 3601 | - // toujours encoder l'url source dans le bloc ajax |
|
| 3602 | - $r = self(); |
|
| 3603 | - $r = ' data-origin="' . $r . '"'; |
|
| 3604 | - $class = 'ajaxbloc'; |
|
| 3605 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 3606 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 3607 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3608 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3609 | - } |
|
| 3610 | - |
|
| 3611 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3530 | + if (is_string($c) |
|
| 3531 | + and @unserialize($c) !== false |
|
| 3532 | + ) { |
|
| 3533 | + $c = unserialize($c); |
|
| 3534 | + } |
|
| 3535 | + |
|
| 3536 | + // supprimer les parametres debut_x |
|
| 3537 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3538 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3539 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3540 | + if (is_array($c)) { |
|
| 3541 | + foreach ($c as $k => $v) { |
|
| 3542 | + if (strpos($k, 'debut_') === 0) { |
|
| 3543 | + unset($c[$k]); |
|
| 3544 | + } |
|
| 3545 | + } |
|
| 3546 | + } |
|
| 3547 | + |
|
| 3548 | + if (!function_exists('calculer_cle_action')) { |
|
| 3549 | + include_spip("inc/securiser_action"); |
|
| 3550 | + } |
|
| 3551 | + |
|
| 3552 | + $c = serialize($c); |
|
| 3553 | + $cle = calculer_cle_action($form . $c); |
|
| 3554 | + $c = "$cle:$c"; |
|
| 3555 | + |
|
| 3556 | + // on ne stocke pas les contextes dans des fichiers caches |
|
| 3557 | + // par defaut, sauf si cette configuration a ete forcee |
|
| 3558 | + // OU que la longueur de l''argument generee est plus long |
|
| 3559 | + // que ce que telere Suhosin. |
|
| 3560 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3561 | + if (!$cache_contextes_ajax) { |
|
| 3562 | + $env = $c; |
|
| 3563 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3564 | + $env = gzdeflate($env); |
|
| 3565 | + // http://core.spip.net/issues/2667 | https://bugs.php.net/bug.php?id=61287 |
|
| 3566 | + if ((PHP_VERSION_ID == 50400) and !@gzinflate($env)) { |
|
| 3567 | + $cache_contextes_ajax = true; |
|
| 3568 | + spip_log("Contextes AJAX forces en fichiers ! Erreur PHP 5.4.0", _LOG_AVERTISSEMENT); |
|
| 3569 | + } |
|
| 3570 | + } |
|
| 3571 | + $env = _xor($env); |
|
| 3572 | + $env = base64_encode($env); |
|
| 3573 | + // tester Suhosin et la valeur maximale des variables en GET... |
|
| 3574 | + if ($max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3575 | + and $max_len < ($len = strlen($env)) |
|
| 3576 | + ) { |
|
| 3577 | + $cache_contextes_ajax = true; |
|
| 3578 | + spip_log("Contextes AJAX forces en fichiers !" |
|
| 3579 | + . " Cela arrive lorsque la valeur du contexte" |
|
| 3580 | + . " depasse la longueur maximale autorisee par Suhosin" |
|
| 3581 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3582 | + . " Vous devriez modifier les parametres de Suhosin" |
|
| 3583 | + . " pour accepter au moins 1024 caracteres.", _LOG_AVERTISSEMENT); |
|
| 3584 | + } |
|
| 3585 | + } |
|
| 3586 | + |
|
| 3587 | + if ($cache_contextes_ajax) { |
|
| 3588 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3589 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3590 | + $md5 = md5($c); |
|
| 3591 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 3592 | + $env = $md5; |
|
| 3593 | + } |
|
| 3594 | + |
|
| 3595 | + if ($emboite === null) { |
|
| 3596 | + return $env; |
|
| 3597 | + } |
|
| 3598 | + if (!trim($emboite)) { |
|
| 3599 | + return ""; |
|
| 3600 | + } |
|
| 3601 | + // toujours encoder l'url source dans le bloc ajax |
|
| 3602 | + $r = self(); |
|
| 3603 | + $r = ' data-origin="' . $r . '"'; |
|
| 3604 | + $class = 'ajaxbloc'; |
|
| 3605 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 3606 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 3607 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 3608 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 3609 | + } |
|
| 3610 | + |
|
| 3611 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3612 | 3612 | } |
| 3613 | 3613 | |
| 3614 | 3614 | /** |
@@ -3628,36 +3628,36 @@ discard block |
||
| 3628 | 3628 | * - false : erreur de décodage |
| 3629 | 3629 | */ |
| 3630 | 3630 | function decoder_contexte_ajax($c, $form = '') { |
| 3631 | - if (!function_exists('calculer_cle_action')) { |
|
| 3632 | - include_spip("inc/securiser_action"); |
|
| 3633 | - } |
|
| 3634 | - if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 3635 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 3636 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 3637 | - ) { |
|
| 3638 | - $c = $contexte; |
|
| 3639 | - } else { |
|
| 3640 | - $c = @base64_decode($c); |
|
| 3641 | - $c = _xor($c); |
|
| 3642 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3643 | - $c = @gzinflate($c); |
|
| 3644 | - } |
|
| 3645 | - } |
|
| 3646 | - |
|
| 3647 | - // extraire la signature en debut de contexte |
|
| 3648 | - // et la verifier avant de deserializer |
|
| 3649 | - // format : signature:donneesserializees |
|
| 3650 | - if ($p = strpos($c,":")){ |
|
| 3651 | - $cle = substr($c,0,$p); |
|
| 3652 | - $c = substr($c,$p+1); |
|
| 3653 | - |
|
| 3654 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 3655 | - $env = @unserialize($c); |
|
| 3656 | - return $env; |
|
| 3657 | - } |
|
| 3658 | - } |
|
| 3659 | - |
|
| 3660 | - return false; |
|
| 3631 | + if (!function_exists('calculer_cle_action')) { |
|
| 3632 | + include_spip("inc/securiser_action"); |
|
| 3633 | + } |
|
| 3634 | + if (((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 3635 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 3636 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 3637 | + ) { |
|
| 3638 | + $c = $contexte; |
|
| 3639 | + } else { |
|
| 3640 | + $c = @base64_decode($c); |
|
| 3641 | + $c = _xor($c); |
|
| 3642 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3643 | + $c = @gzinflate($c); |
|
| 3644 | + } |
|
| 3645 | + } |
|
| 3646 | + |
|
| 3647 | + // extraire la signature en debut de contexte |
|
| 3648 | + // et la verifier avant de deserializer |
|
| 3649 | + // format : signature:donneesserializees |
|
| 3650 | + if ($p = strpos($c,":")){ |
|
| 3651 | + $cle = substr($c,0,$p); |
|
| 3652 | + $c = substr($c,$p+1); |
|
| 3653 | + |
|
| 3654 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 3655 | + $env = @unserialize($c); |
|
| 3656 | + return $env; |
|
| 3657 | + } |
|
| 3658 | + } |
|
| 3659 | + |
|
| 3660 | + return false; |
|
| 3661 | 3661 | } |
| 3662 | 3662 | |
| 3663 | 3663 | |
@@ -3675,20 +3675,20 @@ discard block |
||
| 3675 | 3675 | * Message décrypté ou encrypté |
| 3676 | 3676 | **/ |
| 3677 | 3677 | function _xor($message, $key = null) { |
| 3678 | - if (is_null($key)) { |
|
| 3679 | - if (!function_exists('calculer_cle_action')) { |
|
| 3680 | - include_spip("inc/securiser_action"); |
|
| 3681 | - } |
|
| 3682 | - $key = pack("H*", calculer_cle_action('_xor')); |
|
| 3683 | - } |
|
| 3678 | + if (is_null($key)) { |
|
| 3679 | + if (!function_exists('calculer_cle_action')) { |
|
| 3680 | + include_spip("inc/securiser_action"); |
|
| 3681 | + } |
|
| 3682 | + $key = pack("H*", calculer_cle_action('_xor')); |
|
| 3683 | + } |
|
| 3684 | 3684 | |
| 3685 | - $keylen = strlen($key); |
|
| 3686 | - $messagelen = strlen($message); |
|
| 3687 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 3688 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 3689 | - } |
|
| 3685 | + $keylen = strlen($key); |
|
| 3686 | + $messagelen = strlen($message); |
|
| 3687 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 3688 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 3689 | + } |
|
| 3690 | 3690 | |
| 3691 | - return $message; |
|
| 3691 | + return $message; |
|
| 3692 | 3692 | } |
| 3693 | 3693 | |
| 3694 | 3694 | /** |
@@ -3746,22 +3746,22 @@ discard block |
||
| 3746 | 3746 | * Code HTML |
| 3747 | 3747 | */ |
| 3748 | 3748 | function lien_ou_expose($url, $libelle = null, $on = false, $class = "", $title = "", $rel = "", $evt = '') { |
| 3749 | - if ($on) { |
|
| 3750 | - $bal = "strong"; |
|
| 3751 | - $att = "class='on'"; |
|
| 3752 | - } else { |
|
| 3753 | - $bal = 'a'; |
|
| 3754 | - $att = "href='$url'" |
|
| 3755 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 3756 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 3757 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 3758 | - . $evt; |
|
| 3759 | - } |
|
| 3760 | - if ($libelle === null) { |
|
| 3761 | - $libelle = $url; |
|
| 3762 | - } |
|
| 3749 | + if ($on) { |
|
| 3750 | + $bal = "strong"; |
|
| 3751 | + $att = "class='on'"; |
|
| 3752 | + } else { |
|
| 3753 | + $bal = 'a'; |
|
| 3754 | + $att = "href='$url'" |
|
| 3755 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 3756 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 3757 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 3758 | + . $evt; |
|
| 3759 | + } |
|
| 3760 | + if ($libelle === null) { |
|
| 3761 | + $libelle = $url; |
|
| 3762 | + } |
|
| 3763 | 3763 | |
| 3764 | - return "<$bal $att>$libelle</$bal>"; |
|
| 3764 | + return "<$bal $att>$libelle</$bal>"; |
|
| 3765 | 3765 | } |
| 3766 | 3766 | |
| 3767 | 3767 | |
@@ -3778,18 +3778,18 @@ discard block |
||
| 3778 | 3778 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 3779 | 3779 | */ |
| 3780 | 3780 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = array()) { |
| 3781 | - if (!$nb = intval($nb)) { |
|
| 3782 | - return ""; |
|
| 3783 | - } |
|
| 3784 | - if (!is_array($vars)) { |
|
| 3785 | - return ""; |
|
| 3786 | - } |
|
| 3787 | - $vars[$var] = $nb; |
|
| 3788 | - if ($nb > 1) { |
|
| 3789 | - return _T($chaine_plusieurs, $vars); |
|
| 3790 | - } else { |
|
| 3791 | - return _T($chaine_un, $vars); |
|
| 3792 | - } |
|
| 3781 | + if (!$nb = intval($nb)) { |
|
| 3782 | + return ""; |
|
| 3783 | + } |
|
| 3784 | + if (!is_array($vars)) { |
|
| 3785 | + return ""; |
|
| 3786 | + } |
|
| 3787 | + $vars[$var] = $nb; |
|
| 3788 | + if ($nb > 1) { |
|
| 3789 | + return _T($chaine_plusieurs, $vars); |
|
| 3790 | + } else { |
|
| 3791 | + return _T($chaine_un, $vars); |
|
| 3792 | + } |
|
| 3793 | 3793 | } |
| 3794 | 3794 | |
| 3795 | 3795 | |
@@ -3814,60 +3814,60 @@ discard block |
||
| 3814 | 3814 | * @return string |
| 3815 | 3815 | */ |
| 3816 | 3816 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 3817 | - if (in_array($fonction, array("del", "supprimer.gif"))) { |
|
| 3818 | - $class .= ' danger'; |
|
| 3819 | - } elseif ($fonction == "rien.gif") { |
|
| 3820 | - $fonction = ""; |
|
| 3821 | - } elseif ($fonction == "delsafe") { |
|
| 3822 | - $fonction = "del"; |
|
| 3823 | - } |
|
| 3824 | - |
|
| 3825 | - // remappage des icone : article-24.png+new => article-new-24.png |
|
| 3826 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 3827 | - list($fond, $fonction) = $icone_renommer($fond, $fonction); |
|
| 3828 | - } |
|
| 3829 | - |
|
| 3830 | - // ajouter le type d'objet dans la class de l'icone |
|
| 3831 | - $class .= " " . substr(basename($fond), 0, -4); |
|
| 3832 | - |
|
| 3833 | - $alt = attribut_html($texte); |
|
| 3834 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 3835 | - |
|
| 3836 | - $ajax = ""; |
|
| 3837 | - if (strpos($class, "ajax") !== false) { |
|
| 3838 | - $ajax = "ajax"; |
|
| 3839 | - if (strpos($class, "preload") !== false) { |
|
| 3840 | - $ajax .= " preload"; |
|
| 3841 | - } |
|
| 3842 | - if (strpos($class, "nocache") !== false) { |
|
| 3843 | - $ajax .= " nocache"; |
|
| 3844 | - } |
|
| 3845 | - $ajax = " class='$ajax'"; |
|
| 3846 | - } |
|
| 3847 | - |
|
| 3848 | - $size = 24; |
|
| 3849 | - if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i", $fond, $match)) { |
|
| 3850 | - $size = $match[1]; |
|
| 3851 | - } |
|
| 3852 | - |
|
| 3853 | - if ($fonction) { |
|
| 3854 | - // 2 images pour composer l'icone : le fond (article) en background, |
|
| 3855 | - // la fonction (new) en image |
|
| 3856 | - $icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n" . |
|
| 3857 | - http_style_background($fond)); |
|
| 3858 | - } else { |
|
| 3859 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 3860 | - } |
|
| 3861 | - |
|
| 3862 | - if ($type == 'lien') { |
|
| 3863 | - return "<span class='icone s$size $class'>" |
|
| 3864 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 3865 | - . $icone |
|
| 3866 | - . "<b>$texte</b>" |
|
| 3867 | - . "</a></span>\n"; |
|
| 3868 | - } else { |
|
| 3869 | - return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt); |
|
| 3870 | - } |
|
| 3817 | + if (in_array($fonction, array("del", "supprimer.gif"))) { |
|
| 3818 | + $class .= ' danger'; |
|
| 3819 | + } elseif ($fonction == "rien.gif") { |
|
| 3820 | + $fonction = ""; |
|
| 3821 | + } elseif ($fonction == "delsafe") { |
|
| 3822 | + $fonction = "del"; |
|
| 3823 | + } |
|
| 3824 | + |
|
| 3825 | + // remappage des icone : article-24.png+new => article-new-24.png |
|
| 3826 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 3827 | + list($fond, $fonction) = $icone_renommer($fond, $fonction); |
|
| 3828 | + } |
|
| 3829 | + |
|
| 3830 | + // ajouter le type d'objet dans la class de l'icone |
|
| 3831 | + $class .= " " . substr(basename($fond), 0, -4); |
|
| 3832 | + |
|
| 3833 | + $alt = attribut_html($texte); |
|
| 3834 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 3835 | + |
|
| 3836 | + $ajax = ""; |
|
| 3837 | + if (strpos($class, "ajax") !== false) { |
|
| 3838 | + $ajax = "ajax"; |
|
| 3839 | + if (strpos($class, "preload") !== false) { |
|
| 3840 | + $ajax .= " preload"; |
|
| 3841 | + } |
|
| 3842 | + if (strpos($class, "nocache") !== false) { |
|
| 3843 | + $ajax .= " nocache"; |
|
| 3844 | + } |
|
| 3845 | + $ajax = " class='$ajax'"; |
|
| 3846 | + } |
|
| 3847 | + |
|
| 3848 | + $size = 24; |
|
| 3849 | + if (preg_match("/-([0-9]{1,3})[.](gif|png)$/i", $fond, $match)) { |
|
| 3850 | + $size = $match[1]; |
|
| 3851 | + } |
|
| 3852 | + |
|
| 3853 | + if ($fonction) { |
|
| 3854 | + // 2 images pour composer l'icone : le fond (article) en background, |
|
| 3855 | + // la fonction (new) en image |
|
| 3856 | + $icone = http_img_pack($fonction, $alt, "width='$size' height='$size'\n" . |
|
| 3857 | + http_style_background($fond)); |
|
| 3858 | + } else { |
|
| 3859 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 3860 | + } |
|
| 3861 | + |
|
| 3862 | + if ($type == 'lien') { |
|
| 3863 | + return "<span class='icone s$size $class'>" |
|
| 3864 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 3865 | + . $icone |
|
| 3866 | + . "<b>$texte</b>" |
|
| 3867 | + . "</a></span>\n"; |
|
| 3868 | + } else { |
|
| 3869 | + return bouton_action("$icone<b>$texte</b>", $lien, "icone s$size $class", $javascript, $alt); |
|
| 3870 | + } |
|
| 3871 | 3871 | } |
| 3872 | 3872 | |
| 3873 | 3873 | /** |
@@ -3891,7 +3891,7 @@ discard block |
||
| 3891 | 3891 | * Code HTML du lien |
| 3892 | 3892 | **/ |
| 3893 | 3893 | function icone_base($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 3894 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 3894 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 3895 | 3895 | } |
| 3896 | 3896 | |
| 3897 | 3897 | /** |
@@ -3926,7 +3926,7 @@ discard block |
||
| 3926 | 3926 | * Code HTML du lien |
| 3927 | 3927 | **/ |
| 3928 | 3928 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 3929 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 3929 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 3930 | 3930 | } |
| 3931 | 3931 | |
| 3932 | 3932 | /** |
@@ -3971,7 +3971,7 @@ discard block |
||
| 3971 | 3971 | * Code HTML du lien |
| 3972 | 3972 | **/ |
| 3973 | 3973 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = "", $class = "", $javascript = "") { |
| 3974 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 3974 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 3975 | 3975 | } |
| 3976 | 3976 | |
| 3977 | 3977 | /** |
@@ -4002,7 +4002,7 @@ discard block |
||
| 4002 | 4002 | * Code HTML du lien |
| 4003 | 4003 | **/ |
| 4004 | 4004 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = "", $class = "", $confirm = "") { |
| 4005 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm); |
|
| 4005 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, "horizontale $class", $confirm); |
|
| 4006 | 4006 | } |
| 4007 | 4007 | |
| 4008 | 4008 | /** |
@@ -4032,7 +4032,7 @@ discard block |
||
| 4032 | 4032 | * Code HTML du lien |
| 4033 | 4033 | */ |
| 4034 | 4034 | function filtre_icone_dist($lien, $texte, $fond, $align = "", $fonction = "", $class = "", $javascript = "") { |
| 4035 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4035 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4036 | 4036 | } |
| 4037 | 4037 | |
| 4038 | 4038 | |
@@ -4080,26 +4080,26 @@ discard block |
||
| 4080 | 4080 | * @return string Code CSS |
| 4081 | 4081 | */ |
| 4082 | 4082 | function bando_images_background() { |
| 4083 | - include_spip('inc/bandeau'); |
|
| 4084 | - // recuperer tous les boutons et leurs images |
|
| 4085 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4083 | + include_spip('inc/bandeau'); |
|
| 4084 | + // recuperer tous les boutons et leurs images |
|
| 4085 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4086 | 4086 | |
| 4087 | - $res = ""; |
|
| 4088 | - foreach ($boutons as $page => $detail) { |
|
| 4089 | - if ($detail->icone and strlen(trim($detail->icone))) { |
|
| 4090 | - $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}"; |
|
| 4091 | - } |
|
| 4092 | - $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones "); |
|
| 4093 | - if (is_array($detail->sousmenu)) { |
|
| 4094 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4095 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4096 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}"; |
|
| 4097 | - } |
|
| 4098 | - } |
|
| 4099 | - } |
|
| 4100 | - } |
|
| 4087 | + $res = ""; |
|
| 4088 | + foreach ($boutons as $page => $detail) { |
|
| 4089 | + if ($detail->icone and strlen(trim($detail->icone))) { |
|
| 4090 | + $res .= "\n.navigation_avec_icones #bando1_$page {background-image:url(" . $detail->icone . ");}"; |
|
| 4091 | + } |
|
| 4092 | + $selecteur = (in_array($page, array('outils_rapides', 'outils_collaboratifs')) ? "" : ".navigation_avec_icones "); |
|
| 4093 | + if (is_array($detail->sousmenu)) { |
|
| 4094 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4095 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4096 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url(" . $sousdetail->icone . ");}"; |
|
| 4097 | + } |
|
| 4098 | + } |
|
| 4099 | + } |
|
| 4100 | + } |
|
| 4101 | 4101 | |
| 4102 | - return $res; |
|
| 4102 | + return $res; |
|
| 4103 | 4103 | } |
| 4104 | 4104 | |
| 4105 | 4105 | /** |
@@ -4118,19 +4118,19 @@ discard block |
||
| 4118 | 4118 | * @return string |
| 4119 | 4119 | */ |
| 4120 | 4120 | function bouton_action($libelle, $url, $class = "", $confirm = "", $title = "", $callback = "") { |
| 4121 | - if ($confirm) { |
|
| 4122 | - $confirm = "confirm(\"" . attribut_html($confirm) . "\")"; |
|
| 4123 | - if ($callback) { |
|
| 4124 | - $callback = "$confirm?($callback):false"; |
|
| 4125 | - } else { |
|
| 4126 | - $callback = $confirm; |
|
| 4127 | - } |
|
| 4128 | - } |
|
| 4129 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ""; |
|
| 4130 | - $title = $title ? " title='$title'" : ""; |
|
| 4121 | + if ($confirm) { |
|
| 4122 | + $confirm = "confirm(\"" . attribut_html($confirm) . "\")"; |
|
| 4123 | + if ($callback) { |
|
| 4124 | + $callback = "$confirm?($callback):false"; |
|
| 4125 | + } else { |
|
| 4126 | + $callback = $confirm; |
|
| 4127 | + } |
|
| 4128 | + } |
|
| 4129 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ""; |
|
| 4130 | + $title = $title ? " title='$title'" : ""; |
|
| 4131 | 4131 | |
| 4132 | - return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4133 | - . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>"; |
|
| 4132 | + return "<form class='bouton_action_post $class' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4133 | + . "<button type='submit' class='submit'$title$onclick>$libelle</button></div></form>"; |
|
| 4134 | 4134 | } |
| 4135 | 4135 | |
| 4136 | 4136 | |
@@ -4142,7 +4142,7 @@ discard block |
||
| 4142 | 4142 | * @return string |
| 4143 | 4143 | */ |
| 4144 | 4144 | function tri_protege_champ($t) { |
| 4145 | - return preg_replace(',[^\s\w.+],', '', $t); |
|
| 4145 | + return preg_replace(',[^\s\w.+],', '', $t); |
|
| 4146 | 4146 | } |
| 4147 | 4147 | |
| 4148 | 4148 | /** |
@@ -4155,34 +4155,34 @@ discard block |
||
| 4155 | 4155 | * @return string |
| 4156 | 4156 | */ |
| 4157 | 4157 | function tri_champ_order($t, $from = null) { |
| 4158 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 4159 | - return "multi"; |
|
| 4160 | - } |
|
| 4161 | - |
|
| 4162 | - $champ = $t; |
|
| 4163 | - |
|
| 4164 | - if (strncmp($t, 'num ', 4) == 0) { |
|
| 4165 | - $champ = substr($t, 4); |
|
| 4166 | - } |
|
| 4167 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 4168 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 4169 | - |
|
| 4170 | - if (is_array($from)) { |
|
| 4171 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4172 | - foreach ($from as $idt => $table_sql) { |
|
| 4173 | - if ($desc = $trouver_table($table_sql) |
|
| 4174 | - and isset($desc['field'][$champ]) |
|
| 4175 | - ) { |
|
| 4176 | - $champ = "$idt.$champ"; |
|
| 4177 | - break; |
|
| 4178 | - } |
|
| 4179 | - } |
|
| 4180 | - } |
|
| 4181 | - if (strncmp($t, 'num ', 4) == 0) { |
|
| 4182 | - return "0+$champ"; |
|
| 4183 | - } else { |
|
| 4184 | - return $champ; |
|
| 4185 | - } |
|
| 4158 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 4159 | + return "multi"; |
|
| 4160 | + } |
|
| 4161 | + |
|
| 4162 | + $champ = $t; |
|
| 4163 | + |
|
| 4164 | + if (strncmp($t, 'num ', 4) == 0) { |
|
| 4165 | + $champ = substr($t, 4); |
|
| 4166 | + } |
|
| 4167 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 4168 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 4169 | + |
|
| 4170 | + if (is_array($from)) { |
|
| 4171 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4172 | + foreach ($from as $idt => $table_sql) { |
|
| 4173 | + if ($desc = $trouver_table($table_sql) |
|
| 4174 | + and isset($desc['field'][$champ]) |
|
| 4175 | + ) { |
|
| 4176 | + $champ = "$idt.$champ"; |
|
| 4177 | + break; |
|
| 4178 | + } |
|
| 4179 | + } |
|
| 4180 | + } |
|
| 4181 | + if (strncmp($t, 'num ', 4) == 0) { |
|
| 4182 | + return "0+$champ"; |
|
| 4183 | + } else { |
|
| 4184 | + return $champ; |
|
| 4185 | + } |
|
| 4186 | 4186 | } |
| 4187 | 4187 | |
| 4188 | 4188 | /** |
@@ -4196,18 +4196,18 @@ discard block |
||
| 4196 | 4196 | * @return string |
| 4197 | 4197 | */ |
| 4198 | 4198 | function tri_champ_select($t) { |
| 4199 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 4200 | - $t = substr($t, 6); |
|
| 4201 | - $t = preg_replace(',\s,', '', $t); |
|
| 4202 | - $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 4199 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 4200 | + $t = substr($t, 6); |
|
| 4201 | + $t = preg_replace(',\s,', '', $t); |
|
| 4202 | + $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 4203 | 4203 | |
| 4204 | - return $t; |
|
| 4205 | - } |
|
| 4206 | - if (trim($t) == 'hasard') { |
|
| 4207 | - return 'rand() AS hasard'; |
|
| 4208 | - } |
|
| 4204 | + return $t; |
|
| 4205 | + } |
|
| 4206 | + if (trim($t) == 'hasard') { |
|
| 4207 | + return 'rand() AS hasard'; |
|
| 4208 | + } |
|
| 4209 | 4209 | |
| 4210 | - return "''"; |
|
| 4210 | + return "''"; |
|
| 4211 | 4211 | } |
| 4212 | 4212 | |
| 4213 | 4213 | |
@@ -4229,78 +4229,78 @@ discard block |
||
| 4229 | 4229 | * @return string |
| 4230 | 4230 | */ |
| 4231 | 4231 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = "") { |
| 4232 | - static $trouver_table = null; |
|
| 4233 | - static $objets; |
|
| 4234 | - |
|
| 4235 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4236 | - $id_objet = intval($id_objet); |
|
| 4237 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4238 | - return ''; |
|
| 4239 | - } |
|
| 4240 | - |
|
| 4241 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4242 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4243 | - return ''; |
|
| 4244 | - } |
|
| 4245 | - |
|
| 4246 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4247 | - if ($info == 'url') { |
|
| 4248 | - return generer_url_entite($id_objet, $type_objet); |
|
| 4249 | - } |
|
| 4250 | - |
|
| 4251 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4252 | - $demande_titre = ($info == 'titre'); |
|
| 4253 | - |
|
| 4254 | - // 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 |
|
| 4255 | - if (!isset($objets[$type_objet][$id_objet]) |
|
| 4256 | - or |
|
| 4257 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4258 | - ) { |
|
| 4259 | - if (!$trouver_table) { |
|
| 4260 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4261 | - } |
|
| 4262 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4263 | - if (!$desc) { |
|
| 4264 | - return $objets[$type_objet] = false; |
|
| 4265 | - } |
|
| 4266 | - |
|
| 4267 | - // Si on demande le titre, on le gere en interne |
|
| 4268 | - $champ_titre = ""; |
|
| 4269 | - if ($demande_titre) { |
|
| 4270 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4271 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4272 | - } |
|
| 4273 | - include_spip('base/abstract_sql'); |
|
| 4274 | - include_spip('base/connect_sql'); |
|
| 4275 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4276 | - '*' . $champ_titre, |
|
| 4277 | - $desc['table_sql'], |
|
| 4278 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4279 | - ); |
|
| 4280 | - } |
|
| 4281 | - |
|
| 4282 | - // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 4283 | - if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) { |
|
| 4284 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]); |
|
| 4285 | - } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 4286 | - else { |
|
| 4287 | - if ($generer = charger_fonction("generer_${info}_entite", '', true)) { |
|
| 4288 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]); |
|
| 4289 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4290 | - else { |
|
| 4291 | - $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : ''); |
|
| 4292 | - } |
|
| 4293 | - } |
|
| 4294 | - |
|
| 4295 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4296 | - if (!$etoile) { |
|
| 4297 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4298 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4299 | - $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet), |
|
| 4300 | - array('id_objet' => $id_objet, 'objet' => $type_objet, '')); |
|
| 4301 | - } |
|
| 4302 | - |
|
| 4303 | - return $info_generee; |
|
| 4232 | + static $trouver_table = null; |
|
| 4233 | + static $objets; |
|
| 4234 | + |
|
| 4235 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4236 | + $id_objet = intval($id_objet); |
|
| 4237 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4238 | + return ''; |
|
| 4239 | + } |
|
| 4240 | + |
|
| 4241 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4242 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4243 | + return ''; |
|
| 4244 | + } |
|
| 4245 | + |
|
| 4246 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4247 | + if ($info == 'url') { |
|
| 4248 | + return generer_url_entite($id_objet, $type_objet); |
|
| 4249 | + } |
|
| 4250 | + |
|
| 4251 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4252 | + $demande_titre = ($info == 'titre'); |
|
| 4253 | + |
|
| 4254 | + // 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 |
|
| 4255 | + if (!isset($objets[$type_objet][$id_objet]) |
|
| 4256 | + or |
|
| 4257 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4258 | + ) { |
|
| 4259 | + if (!$trouver_table) { |
|
| 4260 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4261 | + } |
|
| 4262 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4263 | + if (!$desc) { |
|
| 4264 | + return $objets[$type_objet] = false; |
|
| 4265 | + } |
|
| 4266 | + |
|
| 4267 | + // Si on demande le titre, on le gere en interne |
|
| 4268 | + $champ_titre = ""; |
|
| 4269 | + if ($demande_titre) { |
|
| 4270 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4271 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4272 | + } |
|
| 4273 | + include_spip('base/abstract_sql'); |
|
| 4274 | + include_spip('base/connect_sql'); |
|
| 4275 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4276 | + '*' . $champ_titre, |
|
| 4277 | + $desc['table_sql'], |
|
| 4278 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4279 | + ); |
|
| 4280 | + } |
|
| 4281 | + |
|
| 4282 | + // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 4283 | + if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) { |
|
| 4284 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet]); |
|
| 4285 | + } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 4286 | + else { |
|
| 4287 | + if ($generer = charger_fonction("generer_${info}_entite", '', true)) { |
|
| 4288 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet]); |
|
| 4289 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4290 | + else { |
|
| 4291 | + $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : ''); |
|
| 4292 | + } |
|
| 4293 | + } |
|
| 4294 | + |
|
| 4295 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4296 | + if (!$etoile) { |
|
| 4297 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4298 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4299 | + $info_generee = appliquer_traitement_champ($info_generee, $info, table_objet($type_objet), |
|
| 4300 | + array('id_objet' => $id_objet, 'objet' => $type_objet, '')); |
|
| 4301 | + } |
|
| 4302 | + |
|
| 4303 | + return $info_generee; |
|
| 4304 | 4304 | } |
| 4305 | 4305 | |
| 4306 | 4306 | /** |
@@ -4314,44 +4314,44 @@ discard block |
||
| 4314 | 4314 | * @return string |
| 4315 | 4315 | */ |
| 4316 | 4316 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = array(), $connect = '') { |
| 4317 | - if (!$champ) { |
|
| 4318 | - return $texte; |
|
| 4319 | - } |
|
| 4317 | + if (!$champ) { |
|
| 4318 | + return $texte; |
|
| 4319 | + } |
|
| 4320 | 4320 | |
| 4321 | - // On charge toujours les filtres de texte car la majorité des traitements les utilisent |
|
| 4322 | - // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4323 | - include_spip('inc/texte'); |
|
| 4321 | + // On charge toujours les filtres de texte car la majorité des traitements les utilisent |
|
| 4322 | + // et il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4323 | + include_spip('inc/texte'); |
|
| 4324 | 4324 | |
| 4325 | - $champ = strtoupper($champ); |
|
| 4326 | - $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; |
|
| 4327 | - if (!$traitements or !is_array($traitements)) { |
|
| 4328 | - return $texte; |
|
| 4329 | - } |
|
| 4325 | + $champ = strtoupper($champ); |
|
| 4326 | + $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; |
|
| 4327 | + if (!$traitements or !is_array($traitements)) { |
|
| 4328 | + return $texte; |
|
| 4329 | + } |
|
| 4330 | 4330 | |
| 4331 | - $traitement = ''; |
|
| 4332 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4333 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4334 | - $table_objet = table_objet($table_objet); |
|
| 4335 | - if (isset($traitements[$table_objet])) { |
|
| 4336 | - $traitement = $traitements[$table_objet]; |
|
| 4337 | - } |
|
| 4338 | - } |
|
| 4339 | - if (!$traitement and isset($traitements[0])) { |
|
| 4340 | - $traitement = $traitements[0]; |
|
| 4341 | - } |
|
| 4342 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4331 | + $traitement = ''; |
|
| 4332 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4333 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4334 | + $table_objet = table_objet($table_objet); |
|
| 4335 | + if (isset($traitements[$table_objet])) { |
|
| 4336 | + $traitement = $traitements[$table_objet]; |
|
| 4337 | + } |
|
| 4338 | + } |
|
| 4339 | + if (!$traitement and isset($traitements[0])) { |
|
| 4340 | + $traitement = $traitements[0]; |
|
| 4341 | + } |
|
| 4342 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4343 | 4343 | |
| 4344 | - if (!$traitement) { |
|
| 4345 | - return $texte; |
|
| 4346 | - } |
|
| 4344 | + if (!$traitement) { |
|
| 4345 | + return $texte; |
|
| 4346 | + } |
|
| 4347 | 4347 | |
| 4348 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4348 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4349 | 4349 | |
| 4350 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4351 | - $Pile = array(0 => $env); |
|
| 4352 | - eval("\$texte = $traitement;"); |
|
| 4350 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4351 | + $Pile = array(0 => $env); |
|
| 4352 | + eval("\$texte = $traitement;"); |
|
| 4353 | 4353 | |
| 4354 | - return $texte; |
|
| 4354 | + return $texte; |
|
| 4355 | 4355 | } |
| 4356 | 4356 | |
| 4357 | 4357 | |
@@ -4365,21 +4365,21 @@ discard block |
||
| 4365 | 4365 | * @return string |
| 4366 | 4366 | */ |
| 4367 | 4367 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4368 | - include_spip('inc/liens'); |
|
| 4369 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4370 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4371 | - // le raccourcis n'est plus valide |
|
| 4372 | - $titre = isset($titre['titre']) ? typo($titre['titre']) : ''; |
|
| 4373 | - // on essaye avec generer_info_entite ? |
|
| 4374 | - if (!strlen($titre) and !$connect) { |
|
| 4375 | - $titre = generer_info_entite($id_objet, $objet, 'titre'); |
|
| 4376 | - } |
|
| 4377 | - if (!strlen($titre)) { |
|
| 4378 | - $titre = _T('info_sans_titre'); |
|
| 4379 | - } |
|
| 4380 | - $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
|
| 4368 | + include_spip('inc/liens'); |
|
| 4369 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4370 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4371 | + // le raccourcis n'est plus valide |
|
| 4372 | + $titre = isset($titre['titre']) ? typo($titre['titre']) : ''; |
|
| 4373 | + // on essaye avec generer_info_entite ? |
|
| 4374 | + if (!strlen($titre) and !$connect) { |
|
| 4375 | + $titre = generer_info_entite($id_objet, $objet, 'titre'); |
|
| 4376 | + } |
|
| 4377 | + if (!strlen($titre)) { |
|
| 4378 | + $titre = _T('info_sans_titre'); |
|
| 4379 | + } |
|
| 4380 | + $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
|
| 4381 | 4381 | |
| 4382 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>"; |
|
| 4382 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . "</a>"; |
|
| 4383 | 4383 | } |
| 4384 | 4384 | |
| 4385 | 4385 | |
@@ -4396,15 +4396,15 @@ discard block |
||
| 4396 | 4396 | * @return string |
| 4397 | 4397 | */ |
| 4398 | 4398 | function wrap($texte, $wrap) { |
| 4399 | - $balises = extraire_balises($wrap); |
|
| 4400 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4401 | - $texte = $wrap . $texte; |
|
| 4402 | - $regs = array_reverse($regs[1]); |
|
| 4403 | - $wrap = "</" . implode("></", $regs) . ">"; |
|
| 4404 | - $texte = $texte . $wrap; |
|
| 4405 | - } |
|
| 4399 | + $balises = extraire_balises($wrap); |
|
| 4400 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4401 | + $texte = $wrap . $texte; |
|
| 4402 | + $regs = array_reverse($regs[1]); |
|
| 4403 | + $wrap = "</" . implode("></", $regs) . ">"; |
|
| 4404 | + $texte = $texte . $wrap; |
|
| 4405 | + } |
|
| 4406 | 4406 | |
| 4407 | - return $texte; |
|
| 4407 | + return $texte; |
|
| 4408 | 4408 | } |
| 4409 | 4409 | |
| 4410 | 4410 | |
@@ -4424,43 +4424,43 @@ discard block |
||
| 4424 | 4424 | * @return array|mixed|string |
| 4425 | 4425 | */ |
| 4426 | 4426 | function filtre_print_dist($u, $join = "<br />", $indent = 0) { |
| 4427 | - if (is_string($u)) { |
|
| 4428 | - $u = typo($u); |
|
| 4427 | + if (is_string($u)) { |
|
| 4428 | + $u = typo($u); |
|
| 4429 | 4429 | |
| 4430 | - return $u; |
|
| 4431 | - } |
|
| 4430 | + return $u; |
|
| 4431 | + } |
|
| 4432 | 4432 | |
| 4433 | - // caster $u en array si besoin |
|
| 4434 | - if (is_object($u)) { |
|
| 4435 | - $u = (array)$u; |
|
| 4436 | - } |
|
| 4433 | + // caster $u en array si besoin |
|
| 4434 | + if (is_object($u)) { |
|
| 4435 | + $u = (array)$u; |
|
| 4436 | + } |
|
| 4437 | 4437 | |
| 4438 | - if (is_array($u)) { |
|
| 4439 | - $out = ""; |
|
| 4440 | - // toutes les cles sont numeriques ? |
|
| 4441 | - // et aucun enfant n'est un tableau |
|
| 4442 | - // liste simple separee par des virgules |
|
| 4443 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4444 | - $array_values = array_map('is_array', $u); |
|
| 4445 | - $object_values = array_map('is_object', $u); |
|
| 4446 | - if (array_sum($numeric_keys) == count($numeric_keys) |
|
| 4447 | - and !array_sum($array_values) |
|
| 4448 | - and !array_sum($object_values) |
|
| 4449 | - ) { |
|
| 4450 | - return join(", ", array_map('filtre_print_dist', $u)); |
|
| 4451 | - } |
|
| 4438 | + if (is_array($u)) { |
|
| 4439 | + $out = ""; |
|
| 4440 | + // toutes les cles sont numeriques ? |
|
| 4441 | + // et aucun enfant n'est un tableau |
|
| 4442 | + // liste simple separee par des virgules |
|
| 4443 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4444 | + $array_values = array_map('is_array', $u); |
|
| 4445 | + $object_values = array_map('is_object', $u); |
|
| 4446 | + if (array_sum($numeric_keys) == count($numeric_keys) |
|
| 4447 | + and !array_sum($array_values) |
|
| 4448 | + and !array_sum($object_values) |
|
| 4449 | + ) { |
|
| 4450 | + return join(", ", array_map('filtre_print_dist', $u)); |
|
| 4451 | + } |
|
| 4452 | 4452 | |
| 4453 | - // sinon on passe a la ligne et on indente |
|
| 4454 | - $i_str = str_pad("", $indent, " "); |
|
| 4455 | - foreach ($u as $k => $v) { |
|
| 4456 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4457 | - } |
|
| 4453 | + // sinon on passe a la ligne et on indente |
|
| 4454 | + $i_str = str_pad("", $indent, " "); |
|
| 4455 | + foreach ($u as $k => $v) { |
|
| 4456 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4457 | + } |
|
| 4458 | 4458 | |
| 4459 | - return $out; |
|
| 4460 | - } |
|
| 4459 | + return $out; |
|
| 4460 | + } |
|
| 4461 | 4461 | |
| 4462 | - // on sait pas quoi faire... |
|
| 4463 | - return $u; |
|
| 4462 | + // on sait pas quoi faire... |
|
| 4463 | + return $u; |
|
| 4464 | 4464 | } |
| 4465 | 4465 | |
| 4466 | 4466 | |
@@ -4473,10 +4473,10 @@ discard block |
||
| 4473 | 4473 | * @return string |
| 4474 | 4474 | */ |
| 4475 | 4475 | function objet_info($objet, $info) { |
| 4476 | - $table = table_objet_sql($objet); |
|
| 4477 | - $infos = lister_tables_objets_sql($table); |
|
| 4476 | + $table = table_objet_sql($objet); |
|
| 4477 | + $infos = lister_tables_objets_sql($table); |
|
| 4478 | 4478 | |
| 4479 | - return (isset($infos[$info]) ? $infos[$info] : ''); |
|
| 4479 | + return (isset($infos[$info]) ? $infos[$info] : ''); |
|
| 4480 | 4480 | } |
| 4481 | 4481 | |
| 4482 | 4482 | /** |
@@ -4491,11 +4491,11 @@ discard block |
||
| 4491 | 4491 | * Texte traduit du comptage, tel que '3 articles' |
| 4492 | 4492 | */ |
| 4493 | 4493 | function objet_afficher_nb($nb, $objet) { |
| 4494 | - if (!$nb) { |
|
| 4495 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4496 | - } else { |
|
| 4497 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb)); |
|
| 4498 | - } |
|
| 4494 | + if (!$nb) { |
|
| 4495 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 4496 | + } else { |
|
| 4497 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), array('nb' => $nb)); |
|
| 4498 | + } |
|
| 4499 | 4499 | } |
| 4500 | 4500 | |
| 4501 | 4501 | /** |
@@ -4506,11 +4506,11 @@ discard block |
||
| 4506 | 4506 | * @return string |
| 4507 | 4507 | */ |
| 4508 | 4508 | function objet_icone($objet, $taille = 24) { |
| 4509 | - $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png"; |
|
| 4510 | - $icone = chemin_image($icone); |
|
| 4511 | - $balise_img = charger_filtre('balise_img'); |
|
| 4509 | + $icone = objet_info($objet, 'icone_objet') . "-" . $taille . ".png"; |
|
| 4510 | + $icone = chemin_image($icone); |
|
| 4511 | + $balise_img = charger_filtre('balise_img'); |
|
| 4512 | 4512 | |
| 4513 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet'))) : ''; |
|
| 4513 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet'))) : ''; |
|
| 4514 | 4514 | } |
| 4515 | 4515 | |
| 4516 | 4516 | /** |
@@ -4531,12 +4531,12 @@ discard block |
||
| 4531 | 4531 | * @return string |
| 4532 | 4532 | */ |
| 4533 | 4533 | function objet_T($objet, $chaine, $args = array(), $options = array()){ |
| 4534 | - $chaine = explode(':',$chaine); |
|
| 4535 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) { |
|
| 4536 | - return $t; |
|
| 4537 | - } |
|
| 4538 | - $chaine = implode(':',$chaine); |
|
| 4539 | - return _T($chaine, $args, $options); |
|
| 4534 | + $chaine = explode(':',$chaine); |
|
| 4535 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, array('force'=>false)))) { |
|
| 4536 | + return $t; |
|
| 4537 | + } |
|
| 4538 | + $chaine = implode(':',$chaine); |
|
| 4539 | + return _T($chaine, $args, $options); |
|
| 4540 | 4540 | } |
| 4541 | 4541 | |
| 4542 | 4542 | /** |
@@ -4550,17 +4550,17 @@ discard block |
||
| 4550 | 4550 | * @return string Code HTML |
| 4551 | 4551 | */ |
| 4552 | 4552 | function insert_head_css_conditionnel($flux) { |
| 4553 | - if (strpos($flux, '<!-- insert_head_css -->') === false |
|
| 4554 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 4555 | - ) { |
|
| 4556 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 4557 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 4558 | - $p = $p1; |
|
| 4559 | - } |
|
| 4560 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 4561 | - } |
|
| 4553 | + if (strpos($flux, '<!-- insert_head_css -->') === false |
|
| 4554 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 4555 | + ) { |
|
| 4556 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 4557 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 4558 | + $p = $p1; |
|
| 4559 | + } |
|
| 4560 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 4561 | + } |
|
| 4562 | 4562 | |
| 4563 | - return $flux; |
|
| 4563 | + return $flux; |
|
| 4564 | 4564 | } |
| 4565 | 4565 | |
| 4566 | 4566 | /** |
@@ -4581,66 +4581,66 @@ discard block |
||
| 4581 | 4581 | * @return string |
| 4582 | 4582 | */ |
| 4583 | 4583 | function produire_fond_statique($fond, $contexte = array(), $options = array(), $connect = '') { |
| 4584 | - if (isset($contexte['format'])) { |
|
| 4585 | - $extension = $contexte['format']; |
|
| 4586 | - unset($contexte['format']); |
|
| 4587 | - } else { |
|
| 4588 | - $extension = "html"; |
|
| 4589 | - if (preg_match(',[.](css|js|json)$,', $fond, $m)) { |
|
| 4590 | - $extension = $m[1]; |
|
| 4591 | - } |
|
| 4592 | - } |
|
| 4593 | - // recuperer le contenu produit par le squelette |
|
| 4594 | - $options['raw'] = true; |
|
| 4595 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 4596 | - |
|
| 4597 | - // calculer le nom de la css |
|
| 4598 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 4599 | - $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond)); |
|
| 4600 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 4601 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" |
|
| 4602 | - . substr(md5($fond . serialize($contexte_implicite) . serialize($contexte) . $connect), 0, 8) |
|
| 4603 | - . ".$extension"; |
|
| 4604 | - |
|
| 4605 | - // mettre a jour le fichier si il n'existe pas |
|
| 4606 | - // ou trop ancien |
|
| 4607 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 4608 | - // et recopie sur le fichier cible uniquement si il change |
|
| 4609 | - if (!file_exists($filename) |
|
| 4610 | - or !file_exists($filename . ".last") |
|
| 4611 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified']) |
|
| 4612 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 4613 | - ) { |
|
| 4614 | - $contenu = $cache['texte']; |
|
| 4615 | - // passer les urls en absolu si c'est une css |
|
| 4616 | - if ($extension == "css") { |
|
| 4617 | - $contenu = urls_absolues_css($contenu, |
|
| 4618 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)); |
|
| 4619 | - } |
|
| 4620 | - |
|
| 4621 | - $comment = ''; |
|
| 4622 | - // ne pas insérer de commentaire si c'est du json |
|
| 4623 | - if ($extension != "json") { |
|
| 4624 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 4625 | - foreach ($contexte as $k => $v) { |
|
| 4626 | - $comment .= ",$k=$v"; |
|
| 4627 | - } |
|
| 4628 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 4629 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 4630 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 4631 | - } |
|
| 4632 | - // et ecrire le fichier |
|
| 4633 | - ecrire_fichier($filename . ".last", $comment . $contenu); |
|
| 4634 | - // regarder si on recopie |
|
| 4635 | - if (!file_exists($filename) |
|
| 4636 | - or md5_file($filename) !== md5_file($filename . ".last") |
|
| 4637 | - ) { |
|
| 4638 | - @copy($filename . ".last", $filename); |
|
| 4639 | - clearstatcache(true, $filename); // eviter que PHP ne reserve le vieux timestamp |
|
| 4640 | - } |
|
| 4641 | - } |
|
| 4642 | - |
|
| 4643 | - return timestamp($filename); |
|
| 4584 | + if (isset($contexte['format'])) { |
|
| 4585 | + $extension = $contexte['format']; |
|
| 4586 | + unset($contexte['format']); |
|
| 4587 | + } else { |
|
| 4588 | + $extension = "html"; |
|
| 4589 | + if (preg_match(',[.](css|js|json)$,', $fond, $m)) { |
|
| 4590 | + $extension = $m[1]; |
|
| 4591 | + } |
|
| 4592 | + } |
|
| 4593 | + // recuperer le contenu produit par le squelette |
|
| 4594 | + $options['raw'] = true; |
|
| 4595 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 4596 | + |
|
| 4597 | + // calculer le nom de la css |
|
| 4598 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 4599 | + $nom_safe = preg_replace(",\W,", '_', str_replace('.', '_', $fond)); |
|
| 4600 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 4601 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" |
|
| 4602 | + . substr(md5($fond . serialize($contexte_implicite) . serialize($contexte) . $connect), 0, 8) |
|
| 4603 | + . ".$extension"; |
|
| 4604 | + |
|
| 4605 | + // mettre a jour le fichier si il n'existe pas |
|
| 4606 | + // ou trop ancien |
|
| 4607 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 4608 | + // et recopie sur le fichier cible uniquement si il change |
|
| 4609 | + if (!file_exists($filename) |
|
| 4610 | + or !file_exists($filename . ".last") |
|
| 4611 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . ".last") < $cache['lastmodified']) |
|
| 4612 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 4613 | + ) { |
|
| 4614 | + $contenu = $cache['texte']; |
|
| 4615 | + // passer les urls en absolu si c'est une css |
|
| 4616 | + if ($extension == "css") { |
|
| 4617 | + $contenu = urls_absolues_css($contenu, |
|
| 4618 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)); |
|
| 4619 | + } |
|
| 4620 | + |
|
| 4621 | + $comment = ''; |
|
| 4622 | + // ne pas insérer de commentaire si c'est du json |
|
| 4623 | + if ($extension != "json") { |
|
| 4624 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 4625 | + foreach ($contexte as $k => $v) { |
|
| 4626 | + $comment .= ",$k=$v"; |
|
| 4627 | + } |
|
| 4628 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 4629 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 4630 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 4631 | + } |
|
| 4632 | + // et ecrire le fichier |
|
| 4633 | + ecrire_fichier($filename . ".last", $comment . $contenu); |
|
| 4634 | + // regarder si on recopie |
|
| 4635 | + if (!file_exists($filename) |
|
| 4636 | + or md5_file($filename) !== md5_file($filename . ".last") |
|
| 4637 | + ) { |
|
| 4638 | + @copy($filename . ".last", $filename); |
|
| 4639 | + clearstatcache(true, $filename); // eviter que PHP ne reserve le vieux timestamp |
|
| 4640 | + } |
|
| 4641 | + } |
|
| 4642 | + |
|
| 4643 | + return timestamp($filename); |
|
| 4644 | 4644 | } |
| 4645 | 4645 | |
| 4646 | 4646 | /** |
@@ -4653,14 +4653,14 @@ discard block |
||
| 4653 | 4653 | * $fichier auquel on a ajouté le timestamp |
| 4654 | 4654 | */ |
| 4655 | 4655 | function timestamp($fichier) { |
| 4656 | - if (!$fichier |
|
| 4657 | - or !file_exists($fichier) |
|
| 4658 | - or !$m = filemtime($fichier) |
|
| 4659 | - ) { |
|
| 4660 | - return $fichier; |
|
| 4661 | - } |
|
| 4656 | + if (!$fichier |
|
| 4657 | + or !file_exists($fichier) |
|
| 4658 | + or !$m = filemtime($fichier) |
|
| 4659 | + ) { |
|
| 4660 | + return $fichier; |
|
| 4661 | + } |
|
| 4662 | 4662 | |
| 4663 | - return "$fichier?$m"; |
|
| 4663 | + return "$fichier?$m"; |
|
| 4664 | 4664 | } |
| 4665 | 4665 | |
| 4666 | 4666 | /** |
@@ -4670,11 +4670,11 @@ discard block |
||
| 4670 | 4670 | * @return string |
| 4671 | 4671 | */ |
| 4672 | 4672 | function supprimer_timestamp($url) { |
| 4673 | - if (strpos($url, "?") === false) { |
|
| 4674 | - return $url; |
|
| 4675 | - } |
|
| 4673 | + if (strpos($url, "?") === false) { |
|
| 4674 | + return $url; |
|
| 4675 | + } |
|
| 4676 | 4676 | |
| 4677 | - return preg_replace(",\?[[:digit:]]+$,", "", $url); |
|
| 4677 | + return preg_replace(",\?[[:digit:]]+$,", "", $url); |
|
| 4678 | 4678 | } |
| 4679 | 4679 | |
| 4680 | 4680 | /** |
@@ -4689,9 +4689,9 @@ discard block |
||
| 4689 | 4689 | * @return string |
| 4690 | 4690 | */ |
| 4691 | 4691 | function filtre_nettoyer_titre_email_dist($titre) { |
| 4692 | - include_spip('inc/envoyer_mail'); |
|
| 4692 | + include_spip('inc/envoyer_mail'); |
|
| 4693 | 4693 | |
| 4694 | - return nettoyer_titre_email($titre); |
|
| 4694 | + return nettoyer_titre_email($titre); |
|
| 4695 | 4695 | } |
| 4696 | 4696 | |
| 4697 | 4697 | /** |
@@ -4713,19 +4713,19 @@ discard block |
||
| 4713 | 4713 | * @return string |
| 4714 | 4714 | */ |
| 4715 | 4715 | function filtre_chercher_rubrique_dist( |
| 4716 | - $titre, |
|
| 4717 | - $id_objet, |
|
| 4718 | - $id_parent, |
|
| 4719 | - $objet, |
|
| 4720 | - $id_secteur, |
|
| 4721 | - $restreint, |
|
| 4722 | - $actionable = false, |
|
| 4723 | - $retour_sans_cadre = false |
|
| 4716 | + $titre, |
|
| 4717 | + $id_objet, |
|
| 4718 | + $id_parent, |
|
| 4719 | + $objet, |
|
| 4720 | + $id_secteur, |
|
| 4721 | + $restreint, |
|
| 4722 | + $actionable = false, |
|
| 4723 | + $retour_sans_cadre = false |
|
| 4724 | 4724 | ) { |
| 4725 | - include_spip('inc/filtres_ecrire'); |
|
| 4725 | + include_spip('inc/filtres_ecrire'); |
|
| 4726 | 4726 | |
| 4727 | - return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable, |
|
| 4728 | - $retour_sans_cadre); |
|
| 4727 | + return chercher_rubrique($titre, $id_objet, $id_parent, $objet, $id_secteur, $restreint, $actionable, |
|
| 4728 | + $retour_sans_cadre); |
|
| 4729 | 4729 | } |
| 4730 | 4730 | |
| 4731 | 4731 | /** |
@@ -4754,56 +4754,56 @@ discard block |
||
| 4754 | 4754 | * Chaîne vide si l'accès est autorisé |
| 4755 | 4755 | */ |
| 4756 | 4756 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 4757 | - if ($ok) { |
|
| 4758 | - return ''; |
|
| 4759 | - } |
|
| 4760 | - |
|
| 4761 | - // Vider tous les tampons |
|
| 4762 | - $level = @ob_get_level(); |
|
| 4763 | - while ($level--) { |
|
| 4764 | - @ob_end_clean(); |
|
| 4765 | - } |
|
| 4766 | - |
|
| 4767 | - include_spip('inc/headers'); |
|
| 4768 | - |
|
| 4769 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 4770 | - if ($url) { |
|
| 4771 | - redirige_par_entete($url, '', $statut); |
|
| 4772 | - } |
|
| 4773 | - |
|
| 4774 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 4775 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 4776 | - $message = $statut; |
|
| 4777 | - $statut = 0; |
|
| 4778 | - } |
|
| 4779 | - if (!$message) { |
|
| 4780 | - $message = ''; |
|
| 4781 | - } |
|
| 4782 | - $statut = intval($statut); |
|
| 4783 | - |
|
| 4784 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 4785 | - if (test_espace_prive()) { |
|
| 4786 | - if (!$statut or !in_array($statut, array(404, 403))) { |
|
| 4787 | - $statut = 403; |
|
| 4788 | - } |
|
| 4789 | - http_status(403); |
|
| 4790 | - $echec = charger_fonction('403', 'exec'); |
|
| 4791 | - $echec($message); |
|
| 4792 | - } else { |
|
| 4793 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 4794 | - if (!$statut) { |
|
| 4795 | - $statut = 404; |
|
| 4796 | - } |
|
| 4797 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 4798 | - http_status($statut); |
|
| 4799 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 4800 | - if ($statut >= 400) { |
|
| 4801 | - echo recuperer_fond("$statut", array('erreur' => $message)); |
|
| 4802 | - } |
|
| 4803 | - } |
|
| 4804 | - |
|
| 4805 | - |
|
| 4806 | - exit; |
|
| 4757 | + if ($ok) { |
|
| 4758 | + return ''; |
|
| 4759 | + } |
|
| 4760 | + |
|
| 4761 | + // Vider tous les tampons |
|
| 4762 | + $level = @ob_get_level(); |
|
| 4763 | + while ($level--) { |
|
| 4764 | + @ob_end_clean(); |
|
| 4765 | + } |
|
| 4766 | + |
|
| 4767 | + include_spip('inc/headers'); |
|
| 4768 | + |
|
| 4769 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 4770 | + if ($url) { |
|
| 4771 | + redirige_par_entete($url, '', $statut); |
|
| 4772 | + } |
|
| 4773 | + |
|
| 4774 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 4775 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 4776 | + $message = $statut; |
|
| 4777 | + $statut = 0; |
|
| 4778 | + } |
|
| 4779 | + if (!$message) { |
|
| 4780 | + $message = ''; |
|
| 4781 | + } |
|
| 4782 | + $statut = intval($statut); |
|
| 4783 | + |
|
| 4784 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 4785 | + if (test_espace_prive()) { |
|
| 4786 | + if (!$statut or !in_array($statut, array(404, 403))) { |
|
| 4787 | + $statut = 403; |
|
| 4788 | + } |
|
| 4789 | + http_status(403); |
|
| 4790 | + $echec = charger_fonction('403', 'exec'); |
|
| 4791 | + $echec($message); |
|
| 4792 | + } else { |
|
| 4793 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 4794 | + if (!$statut) { |
|
| 4795 | + $statut = 404; |
|
| 4796 | + } |
|
| 4797 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 4798 | + http_status($statut); |
|
| 4799 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 4800 | + if ($statut >= 400) { |
|
| 4801 | + echo recuperer_fond("$statut", array('erreur' => $message)); |
|
| 4802 | + } |
|
| 4803 | + } |
|
| 4804 | + |
|
| 4805 | + |
|
| 4806 | + exit; |
|
| 4807 | 4807 | } |
| 4808 | 4808 | |
| 4809 | 4809 | /** |
@@ -4814,9 +4814,9 @@ discard block |
||
| 4814 | 4814 | * @return string |
| 4815 | 4815 | */ |
| 4816 | 4816 | function filtre_compacte_dist($source, $format = null) { |
| 4817 | - if (function_exists('compacte')) { |
|
| 4818 | - return compacte($source, $format); |
|
| 4819 | - } |
|
| 4817 | + if (function_exists('compacte')) { |
|
| 4818 | + return compacte($source, $format); |
|
| 4819 | + } |
|
| 4820 | 4820 | |
| 4821 | - return $source; |
|
| 4821 | + return $source; |
|
| 4822 | 4822 | } |
@@ -234,6 +234,9 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | |
| 236 | 236 | // http://code.spip.net/@info_etape |
| 237 | +/** |
|
| 238 | + * @param string $titre |
|
| 239 | + */ |
|
| 237 | 240 | function info_etape($titre, $complement = '') { |
| 238 | 241 | return "<h2>" . $titre . "</h2>\n" . |
| 239 | 242 | ($complement ? "" . $complement . "\n" : ''); |
@@ -259,6 +262,11 @@ discard block |
||
| 259 | 262 | } |
| 260 | 263 | |
| 261 | 264 | // http://code.spip.net/@info_progression_etape |
| 265 | +/** |
|
| 266 | + * @param integer $en_cours |
|
| 267 | + * @param string $phase |
|
| 268 | + * @param string $dir |
|
| 269 | + */ |
|
| 262 | 270 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 263 | 271 | //$en_cours = _request('etape')?_request('etape'):""; |
| 264 | 272 | $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
@@ -315,6 +323,9 @@ discard block |
||
| 315 | 323 | |
| 316 | 324 | |
| 317 | 325 | // http://code.spip.net/@fieldset |
| 326 | +/** |
|
| 327 | + * @param string $legend |
|
| 328 | + */ |
|
| 318 | 329 | function fieldset($legend, $champs = array(), $apres = '', $avant = '') { |
| 319 | 330 | return "<fieldset>\n" . |
| 320 | 331 | $avant . |
@@ -382,6 +393,10 @@ discard block |
||
| 382 | 393 | } |
| 383 | 394 | |
| 384 | 395 | // http://code.spip.net/@install_connexion_form |
| 396 | +/** |
|
| 397 | + * @param string[] $pass |
|
| 398 | + * @param integer $etape |
|
| 399 | + */ |
|
| 385 | 400 | function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true) { |
| 386 | 401 | $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
| 387 | 402 | |
@@ -549,6 +564,9 @@ discard block |
||
| 549 | 564 | return array($checked, $bases); |
| 550 | 565 | } |
| 551 | 566 | |
| 567 | +/** |
|
| 568 | + * @param string[] $hidden |
|
| 569 | + */ |
|
| 552 | 570 | function install_propager($hidden) { |
| 553 | 571 | $res = ''; |
| 554 | 572 | foreach ($hidden as $k) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | * @return void |
| 44 | 44 | **/ |
| 45 | 45 | function install_fichier_connexion($nom, $texte) { |
| 46 | - $texte = "<" . "?php\n" |
|
| 47 | - . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | - . $texte |
|
| 49 | - . "?" . ">"; |
|
| 46 | + $texte = "<" . "?php\n" |
|
| 47 | + . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | + . $texte |
|
| 49 | + . "?" . ">"; |
|
| 50 | 50 | |
| 51 | - ecrire_fichier($nom, $texte); |
|
| 51 | + ecrire_fichier($nom, $texte); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -77,20 +77,20 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | **/ |
| 79 | 79 | function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap = '', $charset = '') { |
| 80 | - $adr = addcslashes($adr, "'\\"); |
|
| 81 | - $port = addcslashes($port, "'\\"); |
|
| 82 | - $login = addcslashes($login, "'\\"); |
|
| 83 | - $pass = addcslashes($pass, "'\\"); |
|
| 84 | - $base = addcslashes($base, "'\\"); |
|
| 85 | - $type = addcslashes($type, "'\\"); |
|
| 86 | - $pref = addcslashes($pref, "'\\"); |
|
| 87 | - $ldap = addcslashes($ldap, "'\\"); |
|
| 88 | - $charset = addcslashes($charset, "'\\"); |
|
| 89 | - |
|
| 90 | - return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 91 | - . "spip_connect_db(" |
|
| 92 | - . "'$adr','$port','$login','$pass','$base'" |
|
| 93 | - . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 80 | + $adr = addcslashes($adr, "'\\"); |
|
| 81 | + $port = addcslashes($port, "'\\"); |
|
| 82 | + $login = addcslashes($login, "'\\"); |
|
| 83 | + $pass = addcslashes($pass, "'\\"); |
|
| 84 | + $base = addcslashes($base, "'\\"); |
|
| 85 | + $type = addcslashes($type, "'\\"); |
|
| 86 | + $pref = addcslashes($pref, "'\\"); |
|
| 87 | + $ldap = addcslashes($ldap, "'\\"); |
|
| 88 | + $charset = addcslashes($charset, "'\\"); |
|
| 89 | + |
|
| 90 | + return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 91 | + . "spip_connect_db(" |
|
| 92 | + . "'$adr','$port','$login','$pass','$base'" |
|
| 93 | + . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
@@ -106,26 +106,26 @@ discard block |
||
| 106 | 106 | * Tableau des informations sur la connexion |
| 107 | 107 | **/ |
| 108 | 108 | function analyse_fichier_connection($file) { |
| 109 | - $s = @join('', file($file)); |
|
| 110 | - if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 111 | - array_shift($regs); |
|
| 112 | - |
|
| 113 | - return $regs; |
|
| 114 | - } else { |
|
| 115 | - $ar = '\s*\'([^\']*)\''; |
|
| 116 | - $r = '\s*,' . $ar; |
|
| 117 | - $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 118 | - if (preg_match($r, $s, $regs)) { |
|
| 119 | - $regs[2] = $regs[1] . (!$regs[2] ? '' : ":" . $regs[2] . ";"); |
|
| 120 | - array_shift($regs); |
|
| 121 | - array_shift($regs); |
|
| 122 | - |
|
| 123 | - return $regs; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - spip_log("$file n'est pas un fichier de connexion"); |
|
| 127 | - |
|
| 128 | - return array(); |
|
| 109 | + $s = @join('', file($file)); |
|
| 110 | + if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 111 | + array_shift($regs); |
|
| 112 | + |
|
| 113 | + return $regs; |
|
| 114 | + } else { |
|
| 115 | + $ar = '\s*\'([^\']*)\''; |
|
| 116 | + $r = '\s*,' . $ar; |
|
| 117 | + $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 118 | + if (preg_match($r, $s, $regs)) { |
|
| 119 | + $regs[2] = $regs[1] . (!$regs[2] ? '' : ":" . $regs[2] . ";"); |
|
| 120 | + array_shift($regs); |
|
| 121 | + array_shift($regs); |
|
| 122 | + |
|
| 123 | + return $regs; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + spip_log("$file n'est pas un fichier de connexion"); |
|
| 127 | + |
|
| 128 | + return array(); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -142,21 +142,21 @@ discard block |
||
| 142 | 142 | * Liste des noms de connecteurs |
| 143 | 143 | **/ |
| 144 | 144 | function bases_referencees($exclu = '') { |
| 145 | - $tables = array(); |
|
| 146 | - foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 147 | - if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 148 | - $tables[] = basename($f, '.php'); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $tables; |
|
| 145 | + $tables = array(); |
|
| 146 | + foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 147 | + if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 148 | + $tables[] = basename($f, '.php'); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $tables; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
| 156 | 156 | function install_mode_appel($server_db, $tout = true) { |
| 157 | - return ($server_db != 'mysql') ? '' |
|
| 158 | - : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 159 | - . test_sql_mode_mysql($server_db)); |
|
| 157 | + return ($server_db != 'mysql') ? '' |
|
| 158 | + : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 159 | + . test_sql_mode_mysql($server_db)); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // |
@@ -164,52 +164,52 @@ discard block |
||
| 164 | 164 | // (sert a l'etape 1 de l'installation) |
| 165 | 165 | // http://code.spip.net/@tester_compatibilite_hebergement |
| 166 | 166 | function tester_compatibilite_hebergement() { |
| 167 | - $err = array(); |
|
| 168 | - |
|
| 169 | - $p = phpversion(); |
|
| 170 | - if (version_compare($p, _PHP_MIN, '<')) { |
|
| 171 | - $err[] = _T('install_php_version', array('version' => $p, 'minimum' => _PHP_MIN)); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 175 | - if ($err) { |
|
| 176 | - die("<div class='error'>" |
|
| 177 | - . "<h3>" . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 178 | - . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // Il faut une base de donnees tout de meme ... |
|
| 182 | - $serveurs = install_select_serveur(); |
|
| 183 | - if (!$serveurs) { |
|
| 184 | - $err[] = _T('install_extension_php_obligatoire') |
|
| 185 | - . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 186 | - . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 187 | - . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // et il faut preg |
|
| 191 | - if (!function_exists('preg_match_all')) { |
|
| 192 | - $err[] = _T('install_extension_php_obligatoire') |
|
| 193 | - . " <a href='http://se.php.net/pcre'>PCRE</a>"; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - // et surtout pas ce mbstring.overload |
|
| 197 | - if ($a = @ini_get('mbstring.func_overload')) { |
|
| 198 | - $err[] = _T('install_extension_mbstring') |
|
| 199 | - . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($err) { |
|
| 203 | - echo "<div class='error'>" |
|
| 204 | - . "<h3>" . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 205 | - foreach ($err as $e) { |
|
| 206 | - echo "<li><strong>$e</strong></li>\n"; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 210 | - # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 211 | - echo "</ul></div>\n"; |
|
| 212 | - } |
|
| 167 | + $err = array(); |
|
| 168 | + |
|
| 169 | + $p = phpversion(); |
|
| 170 | + if (version_compare($p, _PHP_MIN, '<')) { |
|
| 171 | + $err[] = _T('install_php_version', array('version' => $p, 'minimum' => _PHP_MIN)); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 175 | + if ($err) { |
|
| 176 | + die("<div class='error'>" |
|
| 177 | + . "<h3>" . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 178 | + . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // Il faut une base de donnees tout de meme ... |
|
| 182 | + $serveurs = install_select_serveur(); |
|
| 183 | + if (!$serveurs) { |
|
| 184 | + $err[] = _T('install_extension_php_obligatoire') |
|
| 185 | + . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 186 | + . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 187 | + . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // et il faut preg |
|
| 191 | + if (!function_exists('preg_match_all')) { |
|
| 192 | + $err[] = _T('install_extension_php_obligatoire') |
|
| 193 | + . " <a href='http://se.php.net/pcre'>PCRE</a>"; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + // et surtout pas ce mbstring.overload |
|
| 197 | + if ($a = @ini_get('mbstring.func_overload')) { |
|
| 198 | + $err[] = _T('install_extension_mbstring') |
|
| 199 | + . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($err) { |
|
| 203 | + echo "<div class='error'>" |
|
| 204 | + . "<h3>" . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 205 | + foreach ($err as $e) { |
|
| 206 | + echo "<li><strong>$e</strong></li>\n"; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 210 | + # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 211 | + echo "</ul></div>\n"; |
|
| 212 | + } |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -219,24 +219,24 @@ discard block |
||
| 219 | 219 | * @note superflu ?? |
| 220 | 220 | */ |
| 221 | 221 | function login_hebergeur() { |
| 222 | - $base_hebergeur = 'localhost'; # par defaut |
|
| 222 | + $base_hebergeur = 'localhost'; # par defaut |
|
| 223 | 223 | |
| 224 | - // Free |
|
| 225 | - if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 226 | - $base_hebergeur = 'sql.free.fr'; |
|
| 227 | - $login_hebergeur = $regs[1]; |
|
| 228 | - } else { |
|
| 229 | - $login_hebergeur = ''; |
|
| 230 | - } |
|
| 224 | + // Free |
|
| 225 | + if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 226 | + $base_hebergeur = 'sql.free.fr'; |
|
| 227 | + $login_hebergeur = $regs[1]; |
|
| 228 | + } else { |
|
| 229 | + $login_hebergeur = ''; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - return array($base_hebergeur, $login_hebergeur); |
|
| 232 | + return array($base_hebergeur, $login_hebergeur); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | |
| 236 | 236 | // http://code.spip.net/@info_etape |
| 237 | 237 | function info_etape($titre, $complement = '') { |
| 238 | - return "<h2>" . $titre . "</h2>\n" . |
|
| 239 | - ($complement ? "" . $complement . "\n" : ''); |
|
| 238 | + return "<h2>" . $titre . "</h2>\n" . |
|
| 239 | + ($complement ? "" . $complement . "\n" : ''); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -246,155 +246,155 @@ discard block |
||
| 246 | 246 | * @return string Code HTML du bouton |
| 247 | 247 | **/ |
| 248 | 248 | function bouton_suivant($code = '') { |
| 249 | - if ($code == '') { |
|
| 250 | - $code = _T('bouton_suivant'); |
|
| 251 | - } |
|
| 252 | - static $suivant = 0; |
|
| 253 | - $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 254 | - $suivant += 1; |
|
| 255 | - |
|
| 256 | - return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 257 | - $code . |
|
| 258 | - " >>\" /></p>\n"; |
|
| 249 | + if ($code == '') { |
|
| 250 | + $code = _T('bouton_suivant'); |
|
| 251 | + } |
|
| 252 | + static $suivant = 0; |
|
| 253 | + $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 254 | + $suivant += 1; |
|
| 255 | + |
|
| 256 | + return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 257 | + $code . |
|
| 258 | + " >>\" /></p>\n"; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // http://code.spip.net/@info_progression_etape |
| 262 | 262 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 263 | - //$en_cours = _request('etape')?_request('etape'):""; |
|
| 264 | - $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 265 | - $debut = 1; |
|
| 266 | - $etat = "ok"; |
|
| 267 | - $last = count($liste); |
|
| 263 | + //$en_cours = _request('etape')?_request('etape'):""; |
|
| 264 | + $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 265 | + $debut = 1; |
|
| 266 | + $etat = "ok"; |
|
| 267 | + $last = count($liste); |
|
| 268 | 268 | // $texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo')); |
| 269 | 269 | |
| 270 | - $intitule_etat["etape_"][1] = typo(_T('info_connexion_base_donnee')); |
|
| 271 | - $intitule_etat["etape_"][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 272 | - $intitule_etat["etape_"][3] = typo(_T('info_informations_personnelles')); |
|
| 273 | - $intitule_etat["etape_"][4] = typo(_T('info_derniere_etape')); |
|
| 270 | + $intitule_etat["etape_"][1] = typo(_T('info_connexion_base_donnee')); |
|
| 271 | + $intitule_etat["etape_"][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 272 | + $intitule_etat["etape_"][3] = typo(_T('info_informations_personnelles')); |
|
| 273 | + $intitule_etat["etape_"][4] = typo(_T('info_derniere_etape')); |
|
| 274 | 274 | |
| 275 | - $intitule_etat["etape_ldap"][1] = typo(_T('titre_connexion_ldap')); |
|
| 276 | - $intitule_etat["etape_ldap"][2] = typo(_T('titre_connexion_ldap')); |
|
| 277 | - $intitule_etat["etape_ldap"][3] = typo(_T('info_chemin_acces_1')); |
|
| 278 | - $intitule_etat["etape_ldap"][4] = typo(_T('info_reglage_ldap')); |
|
| 279 | - $intitule_etat["etape_ldap"][5] = typo(_T('info_ldap_ok')); |
|
| 275 | + $intitule_etat["etape_ldap"][1] = typo(_T('titre_connexion_ldap')); |
|
| 276 | + $intitule_etat["etape_ldap"][2] = typo(_T('titre_connexion_ldap')); |
|
| 277 | + $intitule_etat["etape_ldap"][3] = typo(_T('info_chemin_acces_1')); |
|
| 278 | + $intitule_etat["etape_ldap"][4] = typo(_T('info_reglage_ldap')); |
|
| 279 | + $intitule_etat["etape_ldap"][5] = typo(_T('info_ldap_ok')); |
|
| 280 | 280 | |
| 281 | 281 | // $aff_etapes = "<span id='etapes'>"; |
| 282 | 282 | |
| 283 | - $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 284 | - |
|
| 285 | - foreach ($liste as $etape => $fichier) { |
|
| 286 | - if ($debut < $last) { |
|
| 287 | - if ($debut == $en_cours && $erreur) { |
|
| 288 | - $class = "on erreur"; |
|
| 289 | - } else { |
|
| 290 | - if ($debut == $en_cours) { |
|
| 291 | - $class = "on"; |
|
| 292 | - } else { |
|
| 293 | - if ($debut > $en_cours) { |
|
| 294 | - $class = "prochains"; |
|
| 295 | - } else { |
|
| 296 | - $class = "valides"; |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 302 | - $aff_etapes .= ($debut == $en_cours) ? "<strong>" : ''; |
|
| 303 | - $aff_etapes .= "<em>" . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 304 | - $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 305 | - $aff_etapes .= ($debut == $en_cours) ? "</strong>" : ''; |
|
| 306 | - $aff_etapes .= "</div></li>"; |
|
| 307 | - } |
|
| 308 | - $debut++; |
|
| 309 | - } |
|
| 310 | - $aff_etapes .= "</ul>"; |
|
| 311 | - $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 312 | - |
|
| 313 | - return $aff_etapes; |
|
| 283 | + $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 284 | + |
|
| 285 | + foreach ($liste as $etape => $fichier) { |
|
| 286 | + if ($debut < $last) { |
|
| 287 | + if ($debut == $en_cours && $erreur) { |
|
| 288 | + $class = "on erreur"; |
|
| 289 | + } else { |
|
| 290 | + if ($debut == $en_cours) { |
|
| 291 | + $class = "on"; |
|
| 292 | + } else { |
|
| 293 | + if ($debut > $en_cours) { |
|
| 294 | + $class = "prochains"; |
|
| 295 | + } else { |
|
| 296 | + $class = "valides"; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 302 | + $aff_etapes .= ($debut == $en_cours) ? "<strong>" : ''; |
|
| 303 | + $aff_etapes .= "<em>" . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 304 | + $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 305 | + $aff_etapes .= ($debut == $en_cours) ? "</strong>" : ''; |
|
| 306 | + $aff_etapes .= "</div></li>"; |
|
| 307 | + } |
|
| 308 | + $debut++; |
|
| 309 | + } |
|
| 310 | + $aff_etapes .= "</ul>"; |
|
| 311 | + $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 312 | + |
|
| 313 | + return $aff_etapes; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | |
| 317 | 317 | // http://code.spip.net/@fieldset |
| 318 | 318 | function fieldset($legend, $champs = array(), $apres = '', $avant = '') { |
| 319 | - return "<fieldset>\n" . |
|
| 320 | - $avant . |
|
| 321 | - ($legend ? "<legend>" . $legend . "</legend>\n" : '') . |
|
| 322 | - fieldset_champs($champs) . |
|
| 323 | - $apres . |
|
| 324 | - "</fieldset>\n"; |
|
| 319 | + return "<fieldset>\n" . |
|
| 320 | + $avant . |
|
| 321 | + ($legend ? "<legend>" . $legend . "</legend>\n" : '') . |
|
| 322 | + fieldset_champs($champs) . |
|
| 323 | + $apres . |
|
| 324 | + "</fieldset>\n"; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | function fieldset_champs($champs = array()) { |
| 328 | - $fieldset = ''; |
|
| 329 | - foreach ($champs as $nom => $contenu) { |
|
| 330 | - $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 331 | - $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 332 | - if (isset($contenu['alternatives'])) { |
|
| 333 | - $fieldset .= $contenu['label'] . "\n"; |
|
| 334 | - foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 335 | - $fieldset .= "<input type='radio' name='" . $nom . |
|
| 336 | - "' id='$nom-$valeur' value='$valeur'" |
|
| 337 | - . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 338 | - . "/>\n"; |
|
| 339 | - $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 340 | - } |
|
| 341 | - $fieldset .= "<br />\n"; |
|
| 342 | - } else { |
|
| 343 | - $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 344 | - $fieldset .= "<input " . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 345 | - . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 346 | - . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : "") |
|
| 347 | - . " />\n"; |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - return $fieldset; |
|
| 328 | + $fieldset = ''; |
|
| 329 | + foreach ($champs as $nom => $contenu) { |
|
| 330 | + $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 331 | + $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 332 | + if (isset($contenu['alternatives'])) { |
|
| 333 | + $fieldset .= $contenu['label'] . "\n"; |
|
| 334 | + foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 335 | + $fieldset .= "<input type='radio' name='" . $nom . |
|
| 336 | + "' id='$nom-$valeur' value='$valeur'" |
|
| 337 | + . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 338 | + . "/>\n"; |
|
| 339 | + $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 340 | + } |
|
| 341 | + $fieldset .= "<br />\n"; |
|
| 342 | + } else { |
|
| 343 | + $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 344 | + $fieldset .= "<input " . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 345 | + . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 346 | + . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : "") |
|
| 347 | + . " />\n"; |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + return $fieldset; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | function install_select_serveur() { |
| 355 | - $options = array(); |
|
| 356 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 357 | - $d = opendir($dir); |
|
| 358 | - if (!$d) { |
|
| 359 | - return array(); |
|
| 360 | - } |
|
| 361 | - while (($f = readdir($d)) !== false) { |
|
| 362 | - if ((preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 363 | - and is_readable($f = $dir . $f) |
|
| 364 | - ) { |
|
| 365 | - require_once($f); |
|
| 366 | - $s = $s[1]; |
|
| 367 | - $v = 'spip_versions_' . $s; |
|
| 368 | - if (function_exists($v) and $v()) { |
|
| 369 | - $titre = _T("install_select_type_$s"); |
|
| 370 | - // proposer mysql par defaut si dispo |
|
| 371 | - $checked = ($s == 'mysql' ? " checked='checked'" : ""); |
|
| 372 | - $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 373 | - . "<label for='$s'>" . ($titre ? $titre : $s) . "</label></li>"; |
|
| 374 | - } else { |
|
| 375 | - spip_log("$s: portage indisponible"); |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - sort($options); |
|
| 380 | - |
|
| 381 | - return $options; |
|
| 355 | + $options = array(); |
|
| 356 | + $dir = _DIR_RESTREINT . 'req/'; |
|
| 357 | + $d = opendir($dir); |
|
| 358 | + if (!$d) { |
|
| 359 | + return array(); |
|
| 360 | + } |
|
| 361 | + while (($f = readdir($d)) !== false) { |
|
| 362 | + if ((preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 363 | + and is_readable($f = $dir . $f) |
|
| 364 | + ) { |
|
| 365 | + require_once($f); |
|
| 366 | + $s = $s[1]; |
|
| 367 | + $v = 'spip_versions_' . $s; |
|
| 368 | + if (function_exists($v) and $v()) { |
|
| 369 | + $titre = _T("install_select_type_$s"); |
|
| 370 | + // proposer mysql par defaut si dispo |
|
| 371 | + $checked = ($s == 'mysql' ? " checked='checked'" : ""); |
|
| 372 | + $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 373 | + . "<label for='$s'>" . ($titre ? $titre : $s) . "</label></li>"; |
|
| 374 | + } else { |
|
| 375 | + spip_log("$s: portage indisponible"); |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + sort($options); |
|
| 380 | + |
|
| 381 | + return $options; |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | // http://code.spip.net/@install_connexion_form |
| 385 | 385 | function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true) { |
| 386 | - $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 387 | - |
|
| 388 | - return generer_form_ecrire('install', ( |
|
| 389 | - "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 390 | - . $hidden |
|
| 391 | - . (_request('echec') ? |
|
| 392 | - ("<p><b>" . _T('avis_connexion_echec_1') . |
|
| 393 | - "</b></p><p>" . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . "</p>") |
|
| 394 | - : "") |
|
| 395 | - |
|
| 396 | - . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 397 | - . http_script(' |
|
| 386 | + $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 387 | + |
|
| 388 | + return generer_form_ecrire('install', ( |
|
| 389 | + "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 390 | + . $hidden |
|
| 391 | + . (_request('echec') ? |
|
| 392 | + ("<p><b>" . _T('avis_connexion_echec_1') . |
|
| 393 | + "</b></p><p>" . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . "</p>") |
|
| 394 | + : "") |
|
| 395 | + |
|
| 396 | + . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 397 | + . http_script(' |
|
| 398 | 398 | jQuery(function($) { |
| 399 | 399 | $("input[type=hidden][name=server_db]").each(function(){ |
| 400 | 400 | if ($(this).attr("value").match("sqlite*")){ |
@@ -417,67 +417,67 @@ discard block |
||
| 417 | 417 | }); |
| 418 | 418 | });') |
| 419 | 419 | |
| 420 | - . ($server_db |
|
| 421 | - ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 422 | - . (($predef[0]) |
|
| 423 | - ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 424 | - : '') |
|
| 425 | - : ('<fieldset><legend>' |
|
| 426 | - . _T('install_select_type_db') |
|
| 427 | - . "</legend>" |
|
| 428 | - . '<p class="explication">' |
|
| 429 | - . _T('install_types_db_connus') |
|
| 430 | - // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 431 | - // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 432 | - . '</p>' |
|
| 433 | - . "\n<div class='p'>\n<ul>\n" |
|
| 434 | - . join("\n", install_select_serveur()) |
|
| 435 | - . "\n</ul>\n</div></fieldset>") |
|
| 436 | - ) |
|
| 437 | - . '<div id="install_adresse_base_hebergeur">' |
|
| 438 | - . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 439 | - . ($predef[1] |
|
| 440 | - ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 441 | - : fieldset(_T('entree_base_donnee_1'), |
|
| 442 | - array( |
|
| 443 | - 'adresse_db' => array( |
|
| 444 | - 'label' => $db[1], |
|
| 445 | - 'valeur' => $db[0] |
|
| 446 | - ), |
|
| 447 | - ) |
|
| 448 | - ) |
|
| 449 | - ) |
|
| 450 | - . '</div>' |
|
| 451 | - |
|
| 452 | - . '<div id="install_login_base_hebergeur">' |
|
| 453 | - . ($predef[2] |
|
| 454 | - ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 455 | - : fieldset(_T('entree_login_connexion_1'), |
|
| 456 | - array( |
|
| 457 | - 'login_db' => array( |
|
| 458 | - 'label' => $login[1], |
|
| 459 | - 'valeur' => $login[0] |
|
| 460 | - ), |
|
| 461 | - ) |
|
| 462 | - ) |
|
| 463 | - ) |
|
| 464 | - . '</div>' |
|
| 465 | - |
|
| 466 | - . '<div id="install_pass_base_hebergeur">' |
|
| 467 | - . ($predef[3] |
|
| 468 | - ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 469 | - : fieldset(_T('entree_mot_passe_1'), |
|
| 470 | - array( |
|
| 471 | - 'pass_db' => array( |
|
| 472 | - 'label' => $pass[1], |
|
| 473 | - 'valeur' => $pass[0] |
|
| 474 | - ), |
|
| 475 | - ) |
|
| 476 | - ) |
|
| 477 | - ) |
|
| 478 | - . '</div>' |
|
| 479 | - |
|
| 480 | - . bouton_suivant())); |
|
| 420 | + . ($server_db |
|
| 421 | + ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 422 | + . (($predef[0]) |
|
| 423 | + ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 424 | + : '') |
|
| 425 | + : ('<fieldset><legend>' |
|
| 426 | + . _T('install_select_type_db') |
|
| 427 | + . "</legend>" |
|
| 428 | + . '<p class="explication">' |
|
| 429 | + . _T('install_types_db_connus') |
|
| 430 | + // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 431 | + // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 432 | + . '</p>' |
|
| 433 | + . "\n<div class='p'>\n<ul>\n" |
|
| 434 | + . join("\n", install_select_serveur()) |
|
| 435 | + . "\n</ul>\n</div></fieldset>") |
|
| 436 | + ) |
|
| 437 | + . '<div id="install_adresse_base_hebergeur">' |
|
| 438 | + . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 439 | + . ($predef[1] |
|
| 440 | + ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 441 | + : fieldset(_T('entree_base_donnee_1'), |
|
| 442 | + array( |
|
| 443 | + 'adresse_db' => array( |
|
| 444 | + 'label' => $db[1], |
|
| 445 | + 'valeur' => $db[0] |
|
| 446 | + ), |
|
| 447 | + ) |
|
| 448 | + ) |
|
| 449 | + ) |
|
| 450 | + . '</div>' |
|
| 451 | + |
|
| 452 | + . '<div id="install_login_base_hebergeur">' |
|
| 453 | + . ($predef[2] |
|
| 454 | + ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 455 | + : fieldset(_T('entree_login_connexion_1'), |
|
| 456 | + array( |
|
| 457 | + 'login_db' => array( |
|
| 458 | + 'label' => $login[1], |
|
| 459 | + 'valeur' => $login[0] |
|
| 460 | + ), |
|
| 461 | + ) |
|
| 462 | + ) |
|
| 463 | + ) |
|
| 464 | + . '</div>' |
|
| 465 | + |
|
| 466 | + . '<div id="install_pass_base_hebergeur">' |
|
| 467 | + . ($predef[3] |
|
| 468 | + ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 469 | + : fieldset(_T('entree_mot_passe_1'), |
|
| 470 | + array( |
|
| 471 | + 'pass_db' => array( |
|
| 472 | + 'label' => $pass[1], |
|
| 473 | + 'valeur' => $pass[0] |
|
| 474 | + ), |
|
| 475 | + ) |
|
| 476 | + ) |
|
| 477 | + ) |
|
| 478 | + . '</div>' |
|
| 479 | + |
|
| 480 | + . bouton_suivant())); |
|
| 481 | 481 | |
| 482 | 482 | } |
| 483 | 483 | |
@@ -486,75 +486,75 @@ discard block |
||
| 486 | 486 | |
| 487 | 487 | // http://code.spip.net/@predef_ou_cache |
| 488 | 488 | function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) { |
| 489 | - return ((defined('_INSTALL_HOST_DB')) |
|
| 490 | - ? '' |
|
| 491 | - : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . "\" />" |
|
| 492 | - ) |
|
| 493 | - . ((defined('_INSTALL_USER_DB')) |
|
| 494 | - ? '' |
|
| 495 | - : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . "\" />" |
|
| 496 | - ) |
|
| 497 | - . ((defined('_INSTALL_PASS_DB')) |
|
| 498 | - ? '' |
|
| 499 | - : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . "\" />" |
|
| 500 | - ) |
|
| 501 | - |
|
| 502 | - . ((defined('_INSTALL_SERVER_DB')) |
|
| 503 | - ? '' |
|
| 504 | - : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . "\" />" |
|
| 505 | - ); |
|
| 489 | + return ((defined('_INSTALL_HOST_DB')) |
|
| 490 | + ? '' |
|
| 491 | + : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . "\" />" |
|
| 492 | + ) |
|
| 493 | + . ((defined('_INSTALL_USER_DB')) |
|
| 494 | + ? '' |
|
| 495 | + : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . "\" />" |
|
| 496 | + ) |
|
| 497 | + . ((defined('_INSTALL_PASS_DB')) |
|
| 498 | + ? '' |
|
| 499 | + : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . "\" />" |
|
| 500 | + ) |
|
| 501 | + |
|
| 502 | + . ((defined('_INSTALL_SERVER_DB')) |
|
| 503 | + ? '' |
|
| 504 | + : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . "\" />" |
|
| 505 | + ); |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | // presentation des bases existantes |
| 509 | 509 | |
| 510 | 510 | // http://code.spip.net/@install_etape_liste_bases |
| 511 | 511 | function install_etape_liste_bases($server_db, $login_db, $disabled = array()) { |
| 512 | - $bases = $checked = array(); |
|
| 513 | - $noms = sql_listdbs($server_db); |
|
| 514 | - if (!$noms) { |
|
| 515 | - return ''; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - foreach ($noms as $nom) { |
|
| 519 | - $id = spip_htmlspecialchars($nom); |
|
| 520 | - $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 521 | - $base = " name=\"choix_db\" value=\"" |
|
| 522 | - . $nom |
|
| 523 | - . '"' |
|
| 524 | - . $dis |
|
| 525 | - . " type='radio' id='$id'"; |
|
| 526 | - $label = "<label for='$id'>" |
|
| 527 | - . ($dis ? "<i>$nom</i>" : $nom) |
|
| 528 | - . "</label>"; |
|
| 529 | - |
|
| 530 | - if (!$checked and !$dis and |
|
| 531 | - (($nom == $login_db) or |
|
| 532 | - ($GLOBALS['table_prefix'] == $nom)) |
|
| 533 | - ) { |
|
| 534 | - $checked = "<input$base checked='checked' />\n$label"; |
|
| 535 | - } else { |
|
| 536 | - $bases[] = "<input$base />\n$label"; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - if (!$bases && !$checked) { |
|
| 541 | - return false; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - if ($checked) { |
|
| 545 | - array_unshift($bases, $checked); |
|
| 546 | - $checked = true; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - return array($checked, $bases); |
|
| 512 | + $bases = $checked = array(); |
|
| 513 | + $noms = sql_listdbs($server_db); |
|
| 514 | + if (!$noms) { |
|
| 515 | + return ''; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + foreach ($noms as $nom) { |
|
| 519 | + $id = spip_htmlspecialchars($nom); |
|
| 520 | + $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 521 | + $base = " name=\"choix_db\" value=\"" |
|
| 522 | + . $nom |
|
| 523 | + . '"' |
|
| 524 | + . $dis |
|
| 525 | + . " type='radio' id='$id'"; |
|
| 526 | + $label = "<label for='$id'>" |
|
| 527 | + . ($dis ? "<i>$nom</i>" : $nom) |
|
| 528 | + . "</label>"; |
|
| 529 | + |
|
| 530 | + if (!$checked and !$dis and |
|
| 531 | + (($nom == $login_db) or |
|
| 532 | + ($GLOBALS['table_prefix'] == $nom)) |
|
| 533 | + ) { |
|
| 534 | + $checked = "<input$base checked='checked' />\n$label"; |
|
| 535 | + } else { |
|
| 536 | + $bases[] = "<input$base />\n$label"; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + if (!$bases && !$checked) { |
|
| 541 | + return false; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + if ($checked) { |
|
| 545 | + array_unshift($bases, $checked); |
|
| 546 | + $checked = true; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + return array($checked, $bases); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | function install_propager($hidden) { |
| 553 | - $res = ''; |
|
| 554 | - foreach ($hidden as $k) { |
|
| 555 | - $v = spip_htmlentities(_request($k)); |
|
| 556 | - $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 557 | - } |
|
| 553 | + $res = ''; |
|
| 554 | + foreach ($hidden as $k) { |
|
| 555 | + $v = spip_htmlentities(_request($k)); |
|
| 556 | + $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 557 | + } |
|
| 558 | 558 | |
| 559 | - return $res; |
|
| 559 | + return $res; |
|
| 560 | 560 | } |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | * @return void |
| 44 | 44 | **/ |
| 45 | 45 | function install_fichier_connexion($nom, $texte) { |
| 46 | - $texte = "<" . "?php\n" |
|
| 46 | + $texte = "<"."?php\n" |
|
| 47 | 47 | . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
| 48 | 48 | . $texte |
| 49 | - . "?" . ">"; |
|
| 49 | + . "?".">"; |
|
| 50 | 50 | |
| 51 | 51 | ecrire_fichier($nom, $texte); |
| 52 | 52 | } |
@@ -113,10 +113,10 @@ discard block |
||
| 113 | 113 | return $regs; |
| 114 | 114 | } else { |
| 115 | 115 | $ar = '\s*\'([^\']*)\''; |
| 116 | - $r = '\s*,' . $ar; |
|
| 116 | + $r = '\s*,'.$ar; |
|
| 117 | 117 | $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
| 118 | 118 | if (preg_match($r, $s, $regs)) { |
| 119 | - $regs[2] = $regs[1] . (!$regs[2] ? '' : ":" . $regs[2] . ";"); |
|
| 119 | + $regs[2] = $regs[1].(!$regs[2] ? '' : ":".$regs[2].";"); |
|
| 120 | 120 | array_shift($regs); |
| 121 | 121 | array_shift($regs); |
| 122 | 122 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | // Si on n'a pas la bonne version de PHP, c'est la fin |
| 175 | 175 | if ($err) { |
| 176 | 176 | die("<div class='error'>" |
| 177 | - . "<h3>" . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 177 | + . "<h3>"._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>" |
|
| 178 | 178 | . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
| 179 | 179 | } |
| 180 | 180 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | if ($err) { |
| 203 | 203 | echo "<div class='error'>" |
| 204 | - . "<h3>" . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 204 | + . "<h3>"._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>"; |
|
| 205 | 205 | foreach ($err as $e) { |
| 206 | 206 | echo "<li><strong>$e</strong></li>\n"; |
| 207 | 207 | } |
@@ -235,8 +235,8 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | // http://code.spip.net/@info_etape |
| 237 | 237 | function info_etape($titre, $complement = '') { |
| 238 | - return "<h2>" . $titre . "</h2>\n" . |
|
| 239 | - ($complement ? "" . $complement . "\n" : ''); |
|
| 238 | + return "<h2>".$titre."</h2>\n". |
|
| 239 | + ($complement ? "".$complement."\n" : ''); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -250,18 +250,18 @@ discard block |
||
| 250 | 250 | $code = _T('bouton_suivant'); |
| 251 | 251 | } |
| 252 | 252 | static $suivant = 0; |
| 253 | - $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 253 | + $id = 'suivant'.(($suivant > 0) ? strval($suivant) : ''); |
|
| 254 | 254 | $suivant += 1; |
| 255 | 255 | |
| 256 | - return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 257 | - $code . |
|
| 256 | + return "\n<p class='boutons suivant'><input id='".$id."' type='submit'\nvalue=\"". |
|
| 257 | + $code. |
|
| 258 | 258 | " >>\" /></p>\n"; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // http://code.spip.net/@info_progression_etape |
| 262 | 262 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 263 | 263 | //$en_cours = _request('etape')?_request('etape'):""; |
| 264 | - $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 264 | + $liste = find_all_in_path($dir, $phase.'(([0-9])+|fin)[.]php$'); |
|
| 265 | 265 | $debut = 1; |
| 266 | 266 | $etat = "ok"; |
| 267 | 267 | $last = count($liste); |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | |
| 301 | 301 | $aff_etapes .= "<li class='$class'><div class='fond'>"; |
| 302 | 302 | $aff_etapes .= ($debut == $en_cours) ? "<strong>" : ''; |
| 303 | - $aff_etapes .= "<em>" . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 303 | + $aff_etapes .= "<em>"._T('etape')." </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 304 | 304 | $aff_etapes .= $intitule_etat["$phase"][$debut]; |
| 305 | 305 | $aff_etapes .= ($debut == $en_cours) ? "</strong>" : ''; |
| 306 | 306 | $aff_etapes .= "</div></li>"; |
@@ -316,11 +316,11 @@ discard block |
||
| 316 | 316 | |
| 317 | 317 | // http://code.spip.net/@fieldset |
| 318 | 318 | function fieldset($legend, $champs = array(), $apres = '', $avant = '') { |
| 319 | - return "<fieldset>\n" . |
|
| 320 | - $avant . |
|
| 321 | - ($legend ? "<legend>" . $legend . "</legend>\n" : '') . |
|
| 322 | - fieldset_champs($champs) . |
|
| 323 | - $apres . |
|
| 319 | + return "<fieldset>\n". |
|
| 320 | + $avant. |
|
| 321 | + ($legend ? "<legend>".$legend."</legend>\n" : ''). |
|
| 322 | + fieldset_champs($champs). |
|
| 323 | + $apres. |
|
| 324 | 324 | "</fieldset>\n"; |
| 325 | 325 | } |
| 326 | 326 | |
@@ -330,18 +330,18 @@ discard block |
||
| 330 | 330 | $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
| 331 | 331 | $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
| 332 | 332 | if (isset($contenu['alternatives'])) { |
| 333 | - $fieldset .= $contenu['label'] . "\n"; |
|
| 333 | + $fieldset .= $contenu['label']."\n"; |
|
| 334 | 334 | foreach ($contenu['alternatives'] as $valeur => $label) { |
| 335 | - $fieldset .= "<input type='radio' name='" . $nom . |
|
| 335 | + $fieldset .= "<input type='radio' name='".$nom. |
|
| 336 | 336 | "' id='$nom-$valeur' value='$valeur'" |
| 337 | 337 | . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
| 338 | 338 | . "/>\n"; |
| 339 | - $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 339 | + $fieldset .= "<label for='$nom-$valeur'>".$label."</label>\n"; |
|
| 340 | 340 | } |
| 341 | 341 | $fieldset .= "<br />\n"; |
| 342 | 342 | } else { |
| 343 | - $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 344 | - $fieldset .= "<input " . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 343 | + $fieldset .= "<label for='".$nom."'>".$contenu['label']."</label>\n"; |
|
| 344 | + $fieldset .= "<input ".$class."type='".$type."' id='".$nom."' name='".$nom."'\nvalue='".$contenu['valeur']."'" |
|
| 345 | 345 | . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
| 346 | 346 | . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : "") |
| 347 | 347 | . " />\n"; |
@@ -353,24 +353,24 @@ discard block |
||
| 353 | 353 | |
| 354 | 354 | function install_select_serveur() { |
| 355 | 355 | $options = array(); |
| 356 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 356 | + $dir = _DIR_RESTREINT.'req/'; |
|
| 357 | 357 | $d = opendir($dir); |
| 358 | 358 | if (!$d) { |
| 359 | 359 | return array(); |
| 360 | 360 | } |
| 361 | 361 | while (($f = readdir($d)) !== false) { |
| 362 | 362 | if ((preg_match('/^(.*)[.]php$/', $f, $s)) |
| 363 | - and is_readable($f = $dir . $f) |
|
| 363 | + and is_readable($f = $dir.$f) |
|
| 364 | 364 | ) { |
| 365 | 365 | require_once($f); |
| 366 | 366 | $s = $s[1]; |
| 367 | - $v = 'spip_versions_' . $s; |
|
| 367 | + $v = 'spip_versions_'.$s; |
|
| 368 | 368 | if (function_exists($v) and $v()) { |
| 369 | 369 | $titre = _T("install_select_type_$s"); |
| 370 | 370 | // proposer mysql par defaut si dispo |
| 371 | 371 | $checked = ($s == 'mysql' ? " checked='checked'" : ""); |
| 372 | 372 | $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
| 373 | - . "<label for='$s'>" . ($titre ? $titre : $s) . "</label></li>"; |
|
| 373 | + . "<label for='$s'>".($titre ? $titre : $s)."</label></li>"; |
|
| 374 | 374 | } else { |
| 375 | 375 | spip_log("$s: portage indisponible"); |
| 376 | 376 | } |
@@ -389,8 +389,8 @@ discard block |
||
| 389 | 389 | "\n<input type='hidden' name='etape' value='$etape' />" |
| 390 | 390 | . $hidden |
| 391 | 391 | . (_request('echec') ? |
| 392 | - ("<p><b>" . _T('avis_connexion_echec_1') . |
|
| 393 | - "</b></p><p>" . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . "</p>") |
|
| 392 | + ("<p><b>"._T('avis_connexion_echec_1'). |
|
| 393 | + "</b></p><p>"._T('avis_connexion_echec_2')."</p><p style='font-size: small;'>"._T('avis_connexion_echec_3')."</p>") |
|
| 394 | 394 | : "") |
| 395 | 395 | |
| 396 | 396 | . ($jquery ? http_script('', 'jquery.js') : '') |
@@ -418,9 +418,9 @@ discard block |
||
| 418 | 418 | });') |
| 419 | 419 | |
| 420 | 420 | . ($server_db |
| 421 | - ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 421 | + ? '<input type="hidden" name="server_db" value="'.$server_db.'" />' |
|
| 422 | 422 | . (($predef[0]) |
| 423 | - ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 423 | + ? ('<h3>'._T('install_serveur_hebergeur').'</h3>') |
|
| 424 | 424 | : '') |
| 425 | 425 | : ('<fieldset><legend>' |
| 426 | 426 | . _T('install_select_type_db') |
@@ -435,9 +435,9 @@ discard block |
||
| 435 | 435 | . "\n</ul>\n</div></fieldset>") |
| 436 | 436 | ) |
| 437 | 437 | . '<div id="install_adresse_base_hebergeur">' |
| 438 | - . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 438 | + . '<p>'._T('texte_connexion_mysql').'</p>' |
|
| 439 | 439 | . ($predef[1] |
| 440 | - ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 440 | + ? '<h3>'._T('install_adresse_base_hebergeur').'</h3>' |
|
| 441 | 441 | : fieldset(_T('entree_base_donnee_1'), |
| 442 | 442 | array( |
| 443 | 443 | 'adresse_db' => array( |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | |
| 452 | 452 | . '<div id="install_login_base_hebergeur">' |
| 453 | 453 | . ($predef[2] |
| 454 | - ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 454 | + ? '<h3>'._T('install_login_base_hebergeur').'</h3>' |
|
| 455 | 455 | : fieldset(_T('entree_login_connexion_1'), |
| 456 | 456 | array( |
| 457 | 457 | 'login_db' => array( |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | |
| 466 | 466 | . '<div id="install_pass_base_hebergeur">' |
| 467 | 467 | . ($predef[3] |
| 468 | - ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 468 | + ? '<h3>'._T('install_pass_base_hebergeur').'</h3>' |
|
| 469 | 469 | : fieldset(_T('entree_mot_passe_1'), |
| 470 | 470 | array( |
| 471 | 471 | 'pass_db' => array( |
@@ -488,20 +488,20 @@ discard block |
||
| 488 | 488 | function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) { |
| 489 | 489 | return ((defined('_INSTALL_HOST_DB')) |
| 490 | 490 | ? '' |
| 491 | - : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . "\" />" |
|
| 491 | + : "\n<input type='hidden' name='adresse_db' value=\"".spip_htmlspecialchars($adresse_db)."\" />" |
|
| 492 | 492 | ) |
| 493 | 493 | . ((defined('_INSTALL_USER_DB')) |
| 494 | 494 | ? '' |
| 495 | - : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . "\" />" |
|
| 495 | + : "\n<input type='hidden' name='login_db' value=\"".spip_htmlspecialchars($login_db)."\" />" |
|
| 496 | 496 | ) |
| 497 | 497 | . ((defined('_INSTALL_PASS_DB')) |
| 498 | 498 | ? '' |
| 499 | - : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . "\" />" |
|
| 499 | + : "\n<input type='hidden' name='pass_db' value=\"".spip_htmlspecialchars($pass_db)."\" />" |
|
| 500 | 500 | ) |
| 501 | 501 | |
| 502 | 502 | . ((defined('_INSTALL_SERVER_DB')) |
| 503 | 503 | ? '' |
| 504 | - : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . "\" />" |
|
| 504 | + : "\n<input type='hidden' name='server_db' value=\"".spip_htmlspecialchars($server_db)."\" />" |
|
| 505 | 505 | ); |
| 506 | 506 | } |
| 507 | 507 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * On ne calcule que la racine pour pour aller vite. |
| 42 | 42 | * |
| 43 | 43 | * @param string $dir Chemin du répertoire |
| 44 | - * @param string $nb_estim_taille Nombre de fichiers maximum pour estimer la taille |
|
| 44 | + * @param integer $nb_estim_taille Nombre de fichiers maximum pour estimer la taille |
|
| 45 | 45 | * @return bool|array |
| 46 | 46 | * |
| 47 | 47 | * - false si le répertoire ne peut pas être ouvert |
@@ -336,6 +336,9 @@ discard block |
||
| 336 | 336 | |
| 337 | 337 | // Calcul des pages : noter dans la base les liens d'invalidation |
| 338 | 338 | // http://code.spip.net/@maj_invalideurs |
| 339 | +/** |
|
| 340 | + * @param string $fichier |
|
| 341 | + */ |
|
| 339 | 342 | function maj_invalideurs($fichier, &$page) { |
| 340 | 343 | } |
| 341 | 344 | |
@@ -17,21 +17,21 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('base/serial'); |
| 24 | 24 | |
| 25 | 25 | /** Estime la taille moyenne d'un fichier cache, pour ne pas les regarder (10ko) */ |
| 26 | 26 | if (!defined('_TAILLE_MOYENNE_FICHIER_CACHE')) { |
| 27 | - define('_TAILLE_MOYENNE_FICHIER_CACHE', 1024 * 10); |
|
| 27 | + define('_TAILLE_MOYENNE_FICHIER_CACHE', 1024 * 10); |
|
| 28 | 28 | } |
| 29 | 29 | /** |
| 30 | 30 | * Si un fichier n'a pas été servi (fileatime) depuis plus d'une heure, on se sent |
| 31 | 31 | * en droit de l'éliminer |
| 32 | 32 | */ |
| 33 | 33 | if (!defined('_AGE_CACHE_ATIME')) { |
| 34 | - define('_AGE_CACHE_ATIME', 3600); |
|
| 34 | + define('_AGE_CACHE_ATIME', 3600); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -48,24 +48,24 @@ discard block |
||
| 48 | 48 | * - array(nombre de fichiers, approximation de la taille en octet) sinon |
| 49 | 49 | **/ |
| 50 | 50 | function nombre_de_fichiers_repertoire($dir, $nb_estim_taille = 20) { |
| 51 | - $taille = 0; // mesurer la taille de N fichiers au hasard dans le repertoire |
|
| 52 | - $nb = $nb_estim_taille; |
|
| 53 | - if (!$h = opendir($dir)) { |
|
| 54 | - return false; |
|
| 55 | - } |
|
| 56 | - $total = 0; |
|
| 57 | - while (($fichier = @readdir($h)) !== false) { |
|
| 58 | - if ($fichier[0] != '.' and !is_dir("$dir/$fichier")) { |
|
| 59 | - $total++; |
|
| 60 | - if ($nb and rand(1, 10) == 1) { |
|
| 61 | - $taille += filesize("$dir/$fichier"); |
|
| 62 | - $nb--; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - closedir($h); |
|
| 67 | - |
|
| 68 | - return array($total, $taille ? $taille / ($nb_estim_taille - $nb) : _TAILLE_MOYENNE_FICHIER_CACHE); |
|
| 51 | + $taille = 0; // mesurer la taille de N fichiers au hasard dans le repertoire |
|
| 52 | + $nb = $nb_estim_taille; |
|
| 53 | + if (!$h = opendir($dir)) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 56 | + $total = 0; |
|
| 57 | + while (($fichier = @readdir($h)) !== false) { |
|
| 58 | + if ($fichier[0] != '.' and !is_dir("$dir/$fichier")) { |
|
| 59 | + $total++; |
|
| 60 | + if ($nb and rand(1, 10) == 1) { |
|
| 61 | + $taille += filesize("$dir/$fichier"); |
|
| 62 | + $nb--; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + closedir($h); |
|
| 67 | + |
|
| 68 | + return array($total, $taille ? $taille / ($nb_estim_taille - $nb) : _TAILLE_MOYENNE_FICHIER_CACHE); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -78,31 +78,31 @@ discard block |
||
| 78 | 78 | * @return int Taille approximative en octets |
| 79 | 79 | **/ |
| 80 | 80 | function taille_du_cache() { |
| 81 | - # check dirs until we reach > 500 files |
|
| 82 | - $t = 0; |
|
| 83 | - $n = 0; |
|
| 84 | - $time = isset($GLOBALS['meta']['cache_mark']) ? $GLOBALS['meta']['cache_mark'] : 0; |
|
| 85 | - for ($i=0; $i < 256; $i++) { |
|
| 86 | - $dir = _DIR_CACHE.sprintf('%02s', dechex($i)); |
|
| 87 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 88 | - while (($f = readdir($d)) !== false) { |
|
| 89 | - if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 90 | - $n++; |
|
| 91 | - if ($a['mtime'] >= $time) { |
|
| 92 | - if ($a['blocks'] > 0) { |
|
| 93 | - $t += 512*$a['blocks']; |
|
| 94 | - } else { |
|
| 95 | - $t += $a['size']; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - if ($n > 500) { |
|
| 102 | - return intval(256*$t/(1+$i)); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - return $t; |
|
| 81 | + # check dirs until we reach > 500 files |
|
| 82 | + $t = 0; |
|
| 83 | + $n = 0; |
|
| 84 | + $time = isset($GLOBALS['meta']['cache_mark']) ? $GLOBALS['meta']['cache_mark'] : 0; |
|
| 85 | + for ($i=0; $i < 256; $i++) { |
|
| 86 | + $dir = _DIR_CACHE.sprintf('%02s', dechex($i)); |
|
| 87 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 88 | + while (($f = readdir($d)) !== false) { |
|
| 89 | + if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 90 | + $n++; |
|
| 91 | + if ($a['mtime'] >= $time) { |
|
| 92 | + if ($a['blocks'] > 0) { |
|
| 93 | + $t += 512*$a['blocks']; |
|
| 94 | + } else { |
|
| 95 | + $t += $a['size']; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + if ($n > 500) { |
|
| 102 | + return intval(256*$t/(1+$i)); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + return $t; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | |
@@ -129,30 +129,30 @@ discard block |
||
| 129 | 129 | * Inutilisé |
| 130 | 130 | **/ |
| 131 | 131 | function suivre_invalideur($cond, $modif = true) { |
| 132 | - if (!$modif) { |
|
| 133 | - return; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // determiner l'objet modifie : forum, article, etc |
|
| 137 | - if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 138 | - $objet = objet_type($r[1]); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 142 | - if (isset($objet)) { |
|
| 143 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 147 | - // n'affecter la meta que si un de ces objets est modifie |
|
| 148 | - if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 149 | - if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 150 | - ecrire_meta('derniere_modif', time()); |
|
| 151 | - } |
|
| 152 | - } // sinon, cas standard, toujours affecter la meta |
|
| 153 | - else { |
|
| 154 | - ecrire_meta('derniere_modif', time()); |
|
| 155 | - } |
|
| 132 | + if (!$modif) { |
|
| 133 | + return; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // determiner l'objet modifie : forum, article, etc |
|
| 137 | + if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 138 | + $objet = objet_type($r[1]); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 142 | + if (isset($objet)) { |
|
| 143 | + ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 147 | + // n'affecter la meta que si un de ces objets est modifie |
|
| 148 | + if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 149 | + if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 150 | + ecrire_meta('derniere_modif', time()); |
|
| 151 | + } |
|
| 152 | + } // sinon, cas standard, toujours affecter la meta |
|
| 153 | + else { |
|
| 154 | + ecrire_meta('derniere_modif', time()); |
|
| 155 | + } |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | |
@@ -177,49 +177,49 @@ discard block |
||
| 177 | 177 | * Nombre de fichiers supprimés |
| 178 | 178 | **/ |
| 179 | 179 | function purger_repertoire($dir, $options = array()) { |
| 180 | - if (!is_dir($dir) or !is_readable($dir)) { |
|
| 181 | - return; |
|
| 182 | - } |
|
| 183 | - $handle = opendir($dir); |
|
| 184 | - if (!$handle) { |
|
| 185 | - return; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $total = 0; |
|
| 189 | - |
|
| 190 | - while (($fichier = @readdir($handle)) !== false) { |
|
| 191 | - // Eviter ".", "..", ".htaccess", ".svn" etc. |
|
| 192 | - if ($fichier[0] == '.') { |
|
| 193 | - continue; |
|
| 194 | - } |
|
| 195 | - $chemin = "$dir/$fichier"; |
|
| 196 | - if (is_file($chemin)) { |
|
| 197 | - if ((!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 198 | - and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 199 | - ) { |
|
| 200 | - supprimer_fichier($chemin); |
|
| 201 | - $total++; |
|
| 202 | - } |
|
| 203 | - } else { |
|
| 204 | - if (is_dir($chemin)) { |
|
| 205 | - $opts = $options; |
|
| 206 | - if (isset($options['limit'])) { |
|
| 207 | - $opts['limit'] = $options['limit'] - $total; |
|
| 208 | - } |
|
| 209 | - $total += purger_repertoire($chemin, $opts); |
|
| 210 | - if (isset($options['subdir']) && $options['subdir']) { |
|
| 211 | - spip_unlink($chemin); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 217 | - break; |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - closedir($handle); |
|
| 221 | - |
|
| 222 | - return $total; |
|
| 180 | + if (!is_dir($dir) or !is_readable($dir)) { |
|
| 181 | + return; |
|
| 182 | + } |
|
| 183 | + $handle = opendir($dir); |
|
| 184 | + if (!$handle) { |
|
| 185 | + return; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $total = 0; |
|
| 189 | + |
|
| 190 | + while (($fichier = @readdir($handle)) !== false) { |
|
| 191 | + // Eviter ".", "..", ".htaccess", ".svn" etc. |
|
| 192 | + if ($fichier[0] == '.') { |
|
| 193 | + continue; |
|
| 194 | + } |
|
| 195 | + $chemin = "$dir/$fichier"; |
|
| 196 | + if (is_file($chemin)) { |
|
| 197 | + if ((!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 198 | + and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 199 | + ) { |
|
| 200 | + supprimer_fichier($chemin); |
|
| 201 | + $total++; |
|
| 202 | + } |
|
| 203 | + } else { |
|
| 204 | + if (is_dir($chemin)) { |
|
| 205 | + $opts = $options; |
|
| 206 | + if (isset($options['limit'])) { |
|
| 207 | + $opts['limit'] = $options['limit'] - $total; |
|
| 208 | + } |
|
| 209 | + $total += purger_repertoire($chemin, $opts); |
|
| 210 | + if (isset($options['subdir']) && $options['subdir']) { |
|
| 211 | + spip_unlink($chemin); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 217 | + break; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + closedir($handle); |
|
| 221 | + |
|
| 222 | + return $total; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -231,15 +231,15 @@ discard block |
||
| 231 | 231 | // http://code.spip.net/@retire_cache |
| 232 | 232 | function retire_cache($cache) { |
| 233 | 233 | |
| 234 | - if (preg_match( |
|
| 235 | - ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 236 | - $cache |
|
| 237 | - )) { |
|
| 238 | - // supprimer le fichier (de facon propre) |
|
| 239 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 240 | - } else { |
|
| 241 | - spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 242 | - } |
|
| 234 | + if (preg_match( |
|
| 235 | + ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 236 | + $cache |
|
| 237 | + )) { |
|
| 238 | + // supprimer le fichier (de facon propre) |
|
| 239 | + supprimer_fichier(_DIR_CACHE . $cache); |
|
| 240 | + } else { |
|
| 241 | + spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 242 | + } |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | ####################################################################### |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | // la meta est toujours false ; mais evitons un bug si elle est appellee |
| 255 | 255 | // http://code.spip.net/@retire_caches |
| 256 | 256 | function retire_caches($chemin = '') { |
| 257 | - if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 258 | - effacer_meta('invalider_caches'); |
|
| 259 | - } # concurrence |
|
| 257 | + if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 258 | + effacer_meta('invalider_caches'); |
|
| 259 | + } # concurrence |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $t = 0; |
| 83 | 83 | $n = 0; |
| 84 | 84 | $time = isset($GLOBALS['meta']['cache_mark']) ? $GLOBALS['meta']['cache_mark'] : 0; |
| 85 | - for ($i=0; $i < 256; $i++) { |
|
| 85 | + for ($i = 0; $i < 256; $i++) { |
|
| 86 | 86 | $dir = _DIR_CACHE.sprintf('%02s', dechex($i)); |
| 87 | 87 | if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
| 88 | 88 | while (($f = readdir($d)) !== false) { |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $n++; |
| 91 | 91 | if ($a['mtime'] >= $time) { |
| 92 | 92 | if ($a['blocks'] > 0) { |
| 93 | - $t += 512*$a['blocks']; |
|
| 93 | + $t += 512 * $a['blocks']; |
|
| 94 | 94 | } else { |
| 95 | 95 | $t += $a['size']; |
| 96 | 96 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | if ($n > 500) { |
| 102 | - return intval(256*$t/(1+$i)); |
|
| 102 | + return intval(256 * $t / (1 + $i)); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | return $t; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | // stocker la date_modif_$objet (ne sert a rien pour le moment) |
| 142 | 142 | if (isset($objet)) { |
| 143 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 143 | + ecrire_meta('derniere_modif_'.$objet, time()); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // si $derniere_modif_invalide est un array('article', 'rubrique') |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $cache |
| 237 | 237 | )) { |
| 238 | 238 | // supprimer le fichier (de facon propre) |
| 239 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 239 | + supprimer_fichier(_DIR_CACHE.$cache); |
|
| 240 | 240 | } else { |
| 241 | 241 | spip_log("Nom de fichier cache incorrect : $cache"); |
| 242 | 242 | } |
@@ -21,6 +21,9 @@ |
||
| 21 | 21 | // |
| 22 | 22 | |
| 23 | 23 | // http://code.spip.net/@image_math |
| 24 | +/** |
|
| 25 | + * @param string $tex |
|
| 26 | + */ |
|
| 24 | 27 | function produire_image_math($tex) { |
| 25 | 28 | |
| 26 | 29 | switch ($GLOBALS['traiter_math']) { |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | // |
| 15 | 15 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 16 | - return; |
|
| 16 | + return; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // |
@@ -23,56 +23,56 @@ discard block |
||
| 23 | 23 | // http://code.spip.net/@image_math |
| 24 | 24 | function produire_image_math($tex) { |
| 25 | 25 | |
| 26 | - switch ($GLOBALS['traiter_math']) { |
|
| 27 | - // Attention: mathml desactiv'e pour l'instant |
|
| 28 | - case 'mathml': |
|
| 29 | - $ext = '.xhtml'; |
|
| 30 | - $server = $GLOBALS['mathml_server']; |
|
| 31 | - break; |
|
| 32 | - case 'tex': |
|
| 33 | - $ext = '.png'; |
|
| 34 | - $server = $GLOBALS['tex_server']; |
|
| 35 | - break; |
|
| 36 | - default: |
|
| 37 | - return $tex; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 41 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 42 | - @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 43 | - } |
|
| 44 | - $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - if (!@file_exists($fichier)) { |
|
| 48 | - // Aller chercher l'image sur le serveur |
|
| 49 | - if ($server) { |
|
| 50 | - spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 51 | - include_spip('inc/distant'); |
|
| 52 | - recuperer_page($url, $fichier); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - // Composer la reponse selon presence ou non de l'image |
|
| 58 | - $tex = entites_html($tex); |
|
| 59 | - if (@file_exists($fichier)) { |
|
| 60 | - |
|
| 61 | - // MathML |
|
| 62 | - if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 63 | - return join(file("$fichier"), ""); |
|
| 64 | - } // TeX |
|
| 65 | - else { |
|
| 66 | - list(, , , $size) = @getimagesize($fichier); |
|
| 67 | - $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 68 | - |
|
| 69 | - return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - } else // pas de fichier |
|
| 73 | - { |
|
| 74 | - return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 75 | - } |
|
| 26 | + switch ($GLOBALS['traiter_math']) { |
|
| 27 | + // Attention: mathml desactiv'e pour l'instant |
|
| 28 | + case 'mathml': |
|
| 29 | + $ext = '.xhtml'; |
|
| 30 | + $server = $GLOBALS['mathml_server']; |
|
| 31 | + break; |
|
| 32 | + case 'tex': |
|
| 33 | + $ext = '.png'; |
|
| 34 | + $server = $GLOBALS['tex_server']; |
|
| 35 | + break; |
|
| 36 | + default: |
|
| 37 | + return $tex; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 41 | + if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 42 | + @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 43 | + } |
|
| 44 | + $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + if (!@file_exists($fichier)) { |
|
| 48 | + // Aller chercher l'image sur le serveur |
|
| 49 | + if ($server) { |
|
| 50 | + spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 51 | + include_spip('inc/distant'); |
|
| 52 | + recuperer_page($url, $fichier); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + // Composer la reponse selon presence ou non de l'image |
|
| 58 | + $tex = entites_html($tex); |
|
| 59 | + if (@file_exists($fichier)) { |
|
| 60 | + |
|
| 61 | + // MathML |
|
| 62 | + if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 63 | + return join(file("$fichier"), ""); |
|
| 64 | + } // TeX |
|
| 65 | + else { |
|
| 66 | + list(, , , $size) = @getimagesize($fichier); |
|
| 67 | + $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 68 | + |
|
| 69 | + return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + } else // pas de fichier |
|
| 73 | + { |
|
| 74 | + return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | } |
| 78 | 78 | |
@@ -108,46 +108,46 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | function traiter_math($letexte, $source = '', $defaire_amp = false) { |
| 110 | 110 | |
| 111 | - $texte_a_voir = $letexte; |
|
| 112 | - while (($debut = strpos($texte_a_voir, "<math>")) !== false) { |
|
| 113 | - if (!$fin = strpos($texte_a_voir, "</math>")) { |
|
| 114 | - $fin = strlen($texte_a_voir); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 118 | - $texte_milieu = substr($texte_a_voir, |
|
| 119 | - $debut + strlen("<math>"), $fin - $debut - strlen("<math>")); |
|
| 120 | - $texte_fin = substr($texte_a_voir, |
|
| 121 | - $fin + strlen("</math>"), strlen($texte_a_voir)); |
|
| 122 | - |
|
| 123 | - // Les doubles $$x^2$$ en mode 'div' |
|
| 124 | - while ((preg_match(",[$][$]([^$]+)[$][$],", $texte_milieu, $regs))) { |
|
| 125 | - $expression = $regs[1]; |
|
| 126 | - if ($defaire_amp) { |
|
| 127 | - $expression = str_replace('&', '&', $expression); |
|
| 128 | - } |
|
| 129 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 130 | - $pos = strpos($texte_milieu, $regs[0]); |
|
| 131 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 132 | - . code_echappement($echap, $source) |
|
| 133 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // Les simples $x^2$ en mode 'span' |
|
| 137 | - while ((preg_match(",[$]([^$]+)[$],", $texte_milieu, $regs))) { |
|
| 138 | - $expression = $regs[1]; |
|
| 139 | - if ($defaire_amp) { |
|
| 140 | - $expression = str_replace('&', '&', $expression); |
|
| 141 | - } |
|
| 142 | - $echap = produire_image_math($expression); |
|
| 143 | - $pos = strpos($texte_milieu, $regs[0]); |
|
| 144 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 145 | - . code_echappement($echap, $source) |
|
| 146 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $texte_a_voir; |
|
| 111 | + $texte_a_voir = $letexte; |
|
| 112 | + while (($debut = strpos($texte_a_voir, "<math>")) !== false) { |
|
| 113 | + if (!$fin = strpos($texte_a_voir, "</math>")) { |
|
| 114 | + $fin = strlen($texte_a_voir); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 118 | + $texte_milieu = substr($texte_a_voir, |
|
| 119 | + $debut + strlen("<math>"), $fin - $debut - strlen("<math>")); |
|
| 120 | + $texte_fin = substr($texte_a_voir, |
|
| 121 | + $fin + strlen("</math>"), strlen($texte_a_voir)); |
|
| 122 | + |
|
| 123 | + // Les doubles $$x^2$$ en mode 'div' |
|
| 124 | + while ((preg_match(",[$][$]([^$]+)[$][$],", $texte_milieu, $regs))) { |
|
| 125 | + $expression = $regs[1]; |
|
| 126 | + if ($defaire_amp) { |
|
| 127 | + $expression = str_replace('&', '&', $expression); |
|
| 128 | + } |
|
| 129 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 130 | + $pos = strpos($texte_milieu, $regs[0]); |
|
| 131 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 132 | + . code_echappement($echap, $source) |
|
| 133 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // Les simples $x^2$ en mode 'span' |
|
| 137 | + while ((preg_match(",[$]([^$]+)[$],", $texte_milieu, $regs))) { |
|
| 138 | + $expression = $regs[1]; |
|
| 139 | + if ($defaire_amp) { |
|
| 140 | + $expression = str_replace('&', '&', $expression); |
|
| 141 | + } |
|
| 142 | + $echap = produire_image_math($expression); |
|
| 143 | + $pos = strpos($texte_milieu, $regs[0]); |
|
| 144 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 145 | + . code_echappement($echap, $source) |
|
| 146 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $texte_a_voir; |
|
| 153 | 153 | } |
@@ -38,16 +38,16 @@ discard block |
||
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // Regarder dans le repertoire local des images TeX et blocs MathML |
| 41 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 41 | + if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) { |
|
| 42 | 42 | @mkdir($dir_tex, _SPIP_CHMOD); |
| 43 | 43 | } |
| 44 | - $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 44 | + $fichier = $dir_tex.md5(trim($tex)).$ext; |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | if (!@file_exists($fichier)) { |
| 48 | 48 | // Aller chercher l'image sur le serveur |
| 49 | 49 | if ($server) { |
| 50 | - spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 50 | + spip_log($url = $server.'?'.rawurlencode($tex)); |
|
| 51 | 51 | include_spip('inc/distant'); |
| 52 | 52 | recuperer_page($url, $fichier); |
| 53 | 53 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | return join(file("$fichier"), ""); |
| 64 | 64 | } // TeX |
| 65 | 65 | else { |
| 66 | - list(, , , $size) = @getimagesize($fichier); |
|
| 66 | + list(,,, $size) = @getimagesize($fichier); |
|
| 67 | 67 | $alt = "alt=\"$tex\" title=\"$tex\""; |
| 68 | 68 | |
| 69 | 69 | return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | if ($defaire_amp) { |
| 127 | 127 | $expression = str_replace('&', '&', $expression); |
| 128 | 128 | } |
| 129 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 129 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($expression)."</p>\n"; |
|
| 130 | 130 | $pos = strpos($texte_milieu, $regs[0]); |
| 131 | 131 | $texte_milieu = substr($texte_milieu, 0, $pos) |
| 132 | 132 | . code_echappement($echap, $source) |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | . substr($texte_milieu, $pos + strlen($regs[0])); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 149 | + $texte_a_voir = $texte_debut.$texte_milieu.$texte_fin; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | return $texte_a_voir; |
@@ -623,11 +623,11 @@ |
||
| 623 | 623 | * |
| 624 | 624 | * @param $liste |
| 625 | 625 | * Liste de description des plugins |
| 626 | - * @param $nom |
|
| 626 | + * @param string $nom |
|
| 627 | 627 | * Le plugin donc on cherche la presence |
| 628 | 628 | * @param $intervalle |
| 629 | 629 | * L'éventuelle intervalle de compatibilité de la dépendance. ex: [1.1.0;] |
| 630 | - * @param $balise |
|
| 630 | + * @param string $balise |
|
| 631 | 631 | * Permet de définir si on teste un utilise ou un nécessite |
| 632 | 632 | * @return string. |
| 633 | 633 | * Vide si ok, |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
@@ -45,26 +45,26 @@ discard block |
||
| 45 | 45 | * @return array |
| 46 | 46 | **/ |
| 47 | 47 | function liste_plugin_files($dir_plugins = null) { |
| 48 | - static $plugin_files = array(); |
|
| 49 | - if (is_null($dir_plugins)) { |
|
| 50 | - $dir_plugins = _DIR_PLUGINS; |
|
| 51 | - } |
|
| 52 | - if (!isset($plugin_files[$dir_plugins]) |
|
| 53 | - or count($plugin_files[$dir_plugins]) == 0 |
|
| 54 | - ) { |
|
| 55 | - $plugin_files[$dir_plugins] = array(); |
|
| 56 | - foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 57 | - $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - sort($plugin_files[$dir_plugins]); |
|
| 61 | - // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 62 | - // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 63 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 64 | - $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return $plugin_files[$dir_plugins]; |
|
| 48 | + static $plugin_files = array(); |
|
| 49 | + if (is_null($dir_plugins)) { |
|
| 50 | + $dir_plugins = _DIR_PLUGINS; |
|
| 51 | + } |
|
| 52 | + if (!isset($plugin_files[$dir_plugins]) |
|
| 53 | + or count($plugin_files[$dir_plugins]) == 0 |
|
| 54 | + ) { |
|
| 55 | + $plugin_files[$dir_plugins] = array(); |
|
| 56 | + foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 57 | + $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + sort($plugin_files[$dir_plugins]); |
|
| 61 | + // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 62 | + // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 63 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 64 | + $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return $plugin_files[$dir_plugins]; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -80,44 +80,44 @@ discard block |
||
| 80 | 80 | * Liste complète des répeertoires |
| 81 | 81 | **/ |
| 82 | 82 | function fast_find_plugin_dirs($dir, $max_prof = 100) { |
| 83 | - $fichiers = array(); |
|
| 84 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 85 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 86 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 87 | - if ($dir == '') { |
|
| 88 | - $dir = '.'; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - if (!is_dir($dir)) { |
|
| 92 | - return $fichiers; |
|
| 93 | - } |
|
| 94 | - if (is_plugin_dir($dir, '')) { |
|
| 95 | - $fichiers[] = $dir; |
|
| 96 | - |
|
| 97 | - return $fichiers; |
|
| 98 | - } |
|
| 99 | - if ($max_prof <= 0) { |
|
| 100 | - return $fichiers; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $subdirs = array(); |
|
| 104 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 105 | - while (($f = readdir($d)) !== false) { |
|
| 106 | - if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 107 | - and $f != 'CVS' |
|
| 108 | - and is_dir($f = "$dir/$f") |
|
| 109 | - ) { |
|
| 110 | - $subdirs[] = $f; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - closedir($d); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - foreach ($subdirs as $d) { |
|
| 117 | - $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $fichiers; |
|
| 83 | + $fichiers = array(); |
|
| 84 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 85 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 86 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 87 | + if ($dir == '') { |
|
| 88 | + $dir = '.'; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + if (!is_dir($dir)) { |
|
| 92 | + return $fichiers; |
|
| 93 | + } |
|
| 94 | + if (is_plugin_dir($dir, '')) { |
|
| 95 | + $fichiers[] = $dir; |
|
| 96 | + |
|
| 97 | + return $fichiers; |
|
| 98 | + } |
|
| 99 | + if ($max_prof <= 0) { |
|
| 100 | + return $fichiers; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $subdirs = array(); |
|
| 104 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 105 | + while (($f = readdir($d)) !== false) { |
|
| 106 | + if ($f[0] != '.' # ignorer . .. .svn etc |
|
| 107 | + and $f != 'CVS' |
|
| 108 | + and is_dir($f = "$dir/$f") |
|
| 109 | + ) { |
|
| 110 | + $subdirs[] = $f; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + closedir($d); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + foreach ($subdirs as $d) { |
|
| 117 | + $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $fichiers; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -138,27 +138,27 @@ discard block |
||
| 138 | 138 | **/ |
| 139 | 139 | function is_plugin_dir($dir, $dir_plugins = null) { |
| 140 | 140 | |
| 141 | - if (is_array($dir)) { |
|
| 142 | - foreach ($dir as $k => $d) { |
|
| 143 | - if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 144 | - unset($dir[$k]); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return $dir; |
|
| 149 | - } |
|
| 150 | - if (is_null($dir_plugins)) { |
|
| 151 | - $dir_plugins = _DIR_PLUGINS; |
|
| 152 | - } |
|
| 153 | - $search = array("$dir_plugins$dir/plugin.xml", "$dir_plugins$dir/paquet.xml"); |
|
| 154 | - |
|
| 155 | - foreach ($search as $s) { |
|
| 156 | - if (file_exists($s)) { |
|
| 157 | - return $dir; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return ''; |
|
| 141 | + if (is_array($dir)) { |
|
| 142 | + foreach ($dir as $k => $d) { |
|
| 143 | + if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 144 | + unset($dir[$k]); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return $dir; |
|
| 149 | + } |
|
| 150 | + if (is_null($dir_plugins)) { |
|
| 151 | + $dir_plugins = _DIR_PLUGINS; |
|
| 152 | + } |
|
| 153 | + $search = array("$dir_plugins$dir/plugin.xml", "$dir_plugins$dir/paquet.xml"); |
|
| 154 | + |
|
| 155 | + foreach ($search as $s) { |
|
| 156 | + if (file_exists($s)) { |
|
| 157 | + return $dir; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return ''; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** Regexp d'extraction des informations d'un intervalle de compatibilité */ |
@@ -185,51 +185,51 @@ discard block |
||
| 185 | 185 | **/ |
| 186 | 186 | function plugin_version_compatible($intervalle, $version, $avec_quoi = '') { |
| 187 | 187 | |
| 188 | - if (!strlen($intervalle)) { |
|
| 189 | - return true; |
|
| 190 | - } |
|
| 191 | - if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 192 | - return false; |
|
| 193 | - } |
|
| 194 | - // Extraction des bornes et traitement de * pour la borne sup : |
|
| 195 | - // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 196 | - $minimum = $regs[1]; |
|
| 197 | - $maximum = $regs[2]; |
|
| 198 | - |
|
| 199 | - // si une version SPIP de compatibilité a été définie (dans |
|
| 200 | - // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 201 | - // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 202 | - // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 203 | - // entre plugins) |
|
| 204 | - if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 205 | - if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 206 | - return true; |
|
| 207 | - } |
|
| 208 | - // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 209 | - // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $minimum_inc = $intervalle{0} == "["; |
|
| 213 | - $maximum_inc = substr($intervalle, -1) == "]"; |
|
| 214 | - |
|
| 215 | - if (strlen($minimum)) { |
|
| 216 | - if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 217 | - return false; |
|
| 218 | - } |
|
| 219 | - if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 220 | - return false; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - if (strlen($maximum)) { |
|
| 224 | - if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 225 | - return false; |
|
| 226 | - } |
|
| 227 | - if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 228 | - return false; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - return true; |
|
| 188 | + if (!strlen($intervalle)) { |
|
| 189 | + return true; |
|
| 190 | + } |
|
| 191 | + if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 194 | + // Extraction des bornes et traitement de * pour la borne sup : |
|
| 195 | + // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 196 | + $minimum = $regs[1]; |
|
| 197 | + $maximum = $regs[2]; |
|
| 198 | + |
|
| 199 | + // si une version SPIP de compatibilité a été définie (dans |
|
| 200 | + // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 201 | + // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 202 | + // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 203 | + // entre plugins) |
|
| 204 | + if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 205 | + if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 206 | + return true; |
|
| 207 | + } |
|
| 208 | + // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 209 | + // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $minimum_inc = $intervalle{0} == "["; |
|
| 213 | + $maximum_inc = substr($intervalle, -1) == "]"; |
|
| 214 | + |
|
| 215 | + if (strlen($minimum)) { |
|
| 216 | + if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 217 | + return false; |
|
| 218 | + } |
|
| 219 | + if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 220 | + return false; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + if (strlen($maximum)) { |
|
| 224 | + if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 227 | + if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 228 | + return false; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + return true; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -246,52 +246,52 @@ discard block |
||
| 246 | 246 | * @return array |
| 247 | 247 | */ |
| 248 | 248 | function liste_plugin_valides($liste_plug, $force = false) { |
| 249 | - $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 250 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 251 | - $infos = array( |
|
| 252 | - // lister les extensions qui sont automatiquement actives |
|
| 253 | - '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 254 | - '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 255 | - ); |
|
| 256 | - |
|
| 257 | - // creer une premiere liste non ordonnee mais qui ne retient |
|
| 258 | - // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 259 | - $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 260 | - $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 261 | - $infos['_DIR_RESTREINT']['SPIP']['chemin'] = array(); |
|
| 262 | - $liste_non_classee = array( |
|
| 263 | - 'SPIP' => array( |
|
| 264 | - 'nom' => 'SPIP', |
|
| 265 | - 'etat' => 'stable', |
|
| 266 | - 'version' => $GLOBALS['spip_version_branche'], |
|
| 267 | - 'dir_type' => '_DIR_RESTREINT', |
|
| 268 | - 'dir' => '', |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - |
|
| 272 | - foreach ($liste_ext as $plug) { |
|
| 273 | - if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 274 | - plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - foreach ($liste_plug as $plug) { |
|
| 278 | - if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 279 | - plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 284 | - $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 285 | - foreach ($liste_plug as $plug) { |
|
| 286 | - if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 287 | - plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - plugin_fixer_procure($liste_non_classee, $infos); |
|
| 293 | - |
|
| 294 | - return array($infos, $liste_non_classee); |
|
| 249 | + $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 250 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 251 | + $infos = array( |
|
| 252 | + // lister les extensions qui sont automatiquement actives |
|
| 253 | + '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 254 | + '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 255 | + ); |
|
| 256 | + |
|
| 257 | + // creer une premiere liste non ordonnee mais qui ne retient |
|
| 258 | + // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 259 | + $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 260 | + $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 261 | + $infos['_DIR_RESTREINT']['SPIP']['chemin'] = array(); |
|
| 262 | + $liste_non_classee = array( |
|
| 263 | + 'SPIP' => array( |
|
| 264 | + 'nom' => 'SPIP', |
|
| 265 | + 'etat' => 'stable', |
|
| 266 | + 'version' => $GLOBALS['spip_version_branche'], |
|
| 267 | + 'dir_type' => '_DIR_RESTREINT', |
|
| 268 | + 'dir' => '', |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + |
|
| 272 | + foreach ($liste_ext as $plug) { |
|
| 273 | + if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 274 | + plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + foreach ($liste_plug as $plug) { |
|
| 278 | + if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 279 | + plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 284 | + $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 285 | + foreach ($liste_plug as $plug) { |
|
| 286 | + if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 287 | + plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + plugin_fixer_procure($liste_non_classee, $infos); |
|
| 293 | + |
|
| 294 | + return array($infos, $liste_non_classee); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -308,25 +308,25 @@ discard block |
||
| 308 | 308 | * @param string $dir_type |
| 309 | 309 | */ |
| 310 | 310 | function plugin_valide_resume(&$liste, $plug, $infos, $dir_type) { |
| 311 | - $i = $infos[$dir_type][$plug]; |
|
| 312 | - if (isset($i['erreur']) and $i['erreur']) { |
|
| 313 | - return; |
|
| 314 | - } |
|
| 315 | - if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 316 | - return; |
|
| 317 | - } |
|
| 318 | - $p = strtoupper($i['prefix']); |
|
| 319 | - if (!isset($liste[$p]) |
|
| 320 | - or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 321 | - ) { |
|
| 322 | - $liste[$p] = array( |
|
| 323 | - 'nom' => $i['nom'], |
|
| 324 | - 'etat' => $i['etat'], |
|
| 325 | - 'version' => $i['version'], |
|
| 326 | - 'dir' => $plug, |
|
| 327 | - 'dir_type' => $dir_type |
|
| 328 | - ); |
|
| 329 | - } |
|
| 311 | + $i = $infos[$dir_type][$plug]; |
|
| 312 | + if (isset($i['erreur']) and $i['erreur']) { |
|
| 313 | + return; |
|
| 314 | + } |
|
| 315 | + if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 316 | + return; |
|
| 317 | + } |
|
| 318 | + $p = strtoupper($i['prefix']); |
|
| 319 | + if (!isset($liste[$p]) |
|
| 320 | + or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 321 | + ) { |
|
| 322 | + $liste[$p] = array( |
|
| 323 | + 'nom' => $i['nom'], |
|
| 324 | + 'etat' => $i['etat'], |
|
| 325 | + 'version' => $i['version'], |
|
| 326 | + 'dir' => $plug, |
|
| 327 | + 'dir_type' => $dir_type |
|
| 328 | + ); |
|
| 329 | + } |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -342,46 +342,46 @@ discard block |
||
| 342 | 342 | * @param array $infos |
| 343 | 343 | */ |
| 344 | 344 | function plugin_fixer_procure(&$liste, &$infos) { |
| 345 | - foreach ($liste as $p => $resume) { |
|
| 346 | - $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 347 | - if (isset($i['procure']) and $i['procure']) { |
|
| 348 | - foreach ($i['procure'] as $procure) { |
|
| 349 | - $p = strtoupper($procure['nom']); |
|
| 350 | - $dir = $resume['dir']; |
|
| 351 | - if ($dir) { |
|
| 352 | - $dir .= "/"; |
|
| 353 | - } |
|
| 354 | - $dir .= "procure:" . $procure['nom']; |
|
| 355 | - |
|
| 356 | - $procure['etat'] = '?'; |
|
| 357 | - $procure['dir_type'] = $resume['dir_type']; |
|
| 358 | - $procure['dir'] = $dir; |
|
| 359 | - |
|
| 360 | - // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 361 | - // on ajoute cette version a la liste |
|
| 362 | - if (!isset($liste[$p]) |
|
| 363 | - or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 364 | - ) { |
|
| 365 | - $liste[$p] = $procure; |
|
| 366 | - |
|
| 367 | - // on fournit une information minimale pour ne pas perturber la compilation |
|
| 368 | - $infos[$resume['dir_type']][$dir] = array( |
|
| 369 | - 'prefix' => $procure['nom'], |
|
| 370 | - 'nom' => $procure['nom'], |
|
| 371 | - 'etat' => $procure['etat'], |
|
| 372 | - 'version' => $procure['version'], |
|
| 373 | - 'chemin' => array(), |
|
| 374 | - 'necessite' => array(), |
|
| 375 | - 'utilise' => array(), |
|
| 376 | - 'lib' => array(), |
|
| 377 | - 'menu' => array(), |
|
| 378 | - 'onglet' => array(), |
|
| 379 | - 'procure' => array(), |
|
| 380 | - ); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - } |
|
| 345 | + foreach ($liste as $p => $resume) { |
|
| 346 | + $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 347 | + if (isset($i['procure']) and $i['procure']) { |
|
| 348 | + foreach ($i['procure'] as $procure) { |
|
| 349 | + $p = strtoupper($procure['nom']); |
|
| 350 | + $dir = $resume['dir']; |
|
| 351 | + if ($dir) { |
|
| 352 | + $dir .= "/"; |
|
| 353 | + } |
|
| 354 | + $dir .= "procure:" . $procure['nom']; |
|
| 355 | + |
|
| 356 | + $procure['etat'] = '?'; |
|
| 357 | + $procure['dir_type'] = $resume['dir_type']; |
|
| 358 | + $procure['dir'] = $dir; |
|
| 359 | + |
|
| 360 | + // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 361 | + // on ajoute cette version a la liste |
|
| 362 | + if (!isset($liste[$p]) |
|
| 363 | + or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 364 | + ) { |
|
| 365 | + $liste[$p] = $procure; |
|
| 366 | + |
|
| 367 | + // on fournit une information minimale pour ne pas perturber la compilation |
|
| 368 | + $infos[$resume['dir_type']][$dir] = array( |
|
| 369 | + 'prefix' => $procure['nom'], |
|
| 370 | + 'nom' => $procure['nom'], |
|
| 371 | + 'etat' => $procure['etat'], |
|
| 372 | + 'version' => $procure['version'], |
|
| 373 | + 'chemin' => array(), |
|
| 374 | + 'necessite' => array(), |
|
| 375 | + 'utilise' => array(), |
|
| 376 | + 'lib' => array(), |
|
| 377 | + 'menu' => array(), |
|
| 378 | + 'onglet' => array(), |
|
| 379 | + 'procure' => array(), |
|
| 380 | + ); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | 385 | } |
| 386 | 386 | |
| 387 | 387 | /** |
@@ -395,19 +395,19 @@ discard block |
||
| 395 | 395 | * @return array |
| 396 | 396 | */ |
| 397 | 397 | function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) { |
| 398 | - foreach ($liste as $prefix => $infos) { |
|
| 399 | - if (!$dir_plugins |
|
| 400 | - or ( |
|
| 401 | - defined($infos['dir_type']) |
|
| 402 | - and constant($infos['dir_type']) == $dir_plugins) |
|
| 403 | - ) { |
|
| 404 | - $liste[$prefix] = $infos['dir']; |
|
| 405 | - } else { |
|
| 406 | - unset($liste[$prefix]); |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - return $liste; |
|
| 398 | + foreach ($liste as $prefix => $infos) { |
|
| 399 | + if (!$dir_plugins |
|
| 400 | + or ( |
|
| 401 | + defined($infos['dir_type']) |
|
| 402 | + and constant($infos['dir_type']) == $dir_plugins) |
|
| 403 | + ) { |
|
| 404 | + $liste[$prefix] = $infos['dir']; |
|
| 405 | + } else { |
|
| 406 | + unset($liste[$prefix]); |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + return $liste; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -422,9 +422,9 @@ discard block |
||
| 422 | 422 | * @return array |
| 423 | 423 | */ |
| 424 | 424 | function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) { |
| 425 | - include_spip('plugins/installer'); |
|
| 425 | + include_spip('plugins/installer'); |
|
| 426 | 426 | |
| 427 | - return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 427 | + return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | /** |
@@ -455,53 +455,53 @@ discard block |
||
| 455 | 455 | * qui n'ont pas satisfait leurs dépendances |
| 456 | 456 | **/ |
| 457 | 457 | function plugin_trier($infos, $liste_non_classee) { |
| 458 | - $toute_la_liste = $liste_non_classee; |
|
| 459 | - $liste = $ordre = array(); |
|
| 460 | - $count = 0; |
|
| 461 | - |
|
| 462 | - while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 463 | - #echo "tour::";var_dump($liste_non_classee); |
|
| 464 | - $count = $c; |
|
| 465 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 466 | - $plug = $resume['dir']; |
|
| 467 | - $dir_type = $resume['dir_type']; |
|
| 468 | - $info1 = $infos[$dir_type][$plug]; |
|
| 469 | - // si des plugins sont necessaires, |
|
| 470 | - // on ne peut inserer qu'apres eux |
|
| 471 | - foreach ($info1['necessite'] as $need) { |
|
| 472 | - $nom = strtoupper($need['nom']); |
|
| 473 | - $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 474 | - if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 475 | - $info1 = false; |
|
| 476 | - break; |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - if (!$info1) { |
|
| 480 | - continue; |
|
| 481 | - } |
|
| 482 | - // idem si des plugins sont utiles, |
|
| 483 | - // sauf si ils sont de toute facon absents de la liste |
|
| 484 | - foreach ($info1['utilise'] as $need) { |
|
| 485 | - $nom = strtoupper($need['nom']); |
|
| 486 | - $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 487 | - if (isset($toute_la_liste[$nom])) { |
|
| 488 | - if (!isset($liste[$nom]) or |
|
| 489 | - !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 490 | - ) { |
|
| 491 | - $info1 = false; |
|
| 492 | - break; |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - if ($info1) { |
|
| 497 | - $ordre[$p] = $info1; |
|
| 498 | - $liste[$p] = $liste_non_classee[$p]; |
|
| 499 | - unset($liste_non_classee[$p]); |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - return array($liste, $ordre, $liste_non_classee); |
|
| 458 | + $toute_la_liste = $liste_non_classee; |
|
| 459 | + $liste = $ordre = array(); |
|
| 460 | + $count = 0; |
|
| 461 | + |
|
| 462 | + while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 463 | + #echo "tour::";var_dump($liste_non_classee); |
|
| 464 | + $count = $c; |
|
| 465 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 466 | + $plug = $resume['dir']; |
|
| 467 | + $dir_type = $resume['dir_type']; |
|
| 468 | + $info1 = $infos[$dir_type][$plug]; |
|
| 469 | + // si des plugins sont necessaires, |
|
| 470 | + // on ne peut inserer qu'apres eux |
|
| 471 | + foreach ($info1['necessite'] as $need) { |
|
| 472 | + $nom = strtoupper($need['nom']); |
|
| 473 | + $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 474 | + if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 475 | + $info1 = false; |
|
| 476 | + break; |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + if (!$info1) { |
|
| 480 | + continue; |
|
| 481 | + } |
|
| 482 | + // idem si des plugins sont utiles, |
|
| 483 | + // sauf si ils sont de toute facon absents de la liste |
|
| 484 | + foreach ($info1['utilise'] as $need) { |
|
| 485 | + $nom = strtoupper($need['nom']); |
|
| 486 | + $compat = isset($need['compatibilite']) ? $need['compatibilite'] : ''; |
|
| 487 | + if (isset($toute_la_liste[$nom])) { |
|
| 488 | + if (!isset($liste[$nom]) or |
|
| 489 | + !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 490 | + ) { |
|
| 491 | + $info1 = false; |
|
| 492 | + break; |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + if ($info1) { |
|
| 497 | + $ordre[$p] = $info1; |
|
| 498 | + $liste[$p] = $liste_non_classee[$p]; |
|
| 499 | + unset($liste_non_classee[$p]); |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + return array($liste, $ordre, $liste_non_classee); |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
@@ -518,34 +518,34 @@ discard block |
||
| 518 | 518 | * Répertoire (plugins, plugins-dist, ...) => Couples (prefixes => infos completes) des plugins qu'ils contiennent |
| 519 | 519 | **/ |
| 520 | 520 | function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = array()) { |
| 521 | - static $erreurs = array(); |
|
| 522 | - |
|
| 523 | - if (!is_array($liste)) { |
|
| 524 | - $liste = array(); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 528 | - $liste = array_diff_key($liste, $liste_non_classee); |
|
| 529 | - |
|
| 530 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 531 | - $dir_type = $resume['dir_type']; |
|
| 532 | - $plug = $resume['dir']; |
|
| 533 | - $k = $infos[$dir_type][$plug]; |
|
| 534 | - |
|
| 535 | - $plug = constant($dir_type) . $plug; |
|
| 536 | - if (!isset($msg[$p])) { |
|
| 537 | - if (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 538 | - $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 539 | - } |
|
| 540 | - } else { |
|
| 541 | - foreach ($msg[$p] as $c => $l) { |
|
| 542 | - $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - $erreurs[$plug] = $msg[$p]; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 521 | + static $erreurs = array(); |
|
| 522 | + |
|
| 523 | + if (!is_array($liste)) { |
|
| 524 | + $liste = array(); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 528 | + $liste = array_diff_key($liste, $liste_non_classee); |
|
| 529 | + |
|
| 530 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 531 | + $dir_type = $resume['dir_type']; |
|
| 532 | + $plug = $resume['dir']; |
|
| 533 | + $k = $infos[$dir_type][$plug]; |
|
| 534 | + |
|
| 535 | + $plug = constant($dir_type) . $plug; |
|
| 536 | + if (!isset($msg[$p])) { |
|
| 537 | + if (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 538 | + $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 539 | + } |
|
| 540 | + } else { |
|
| 541 | + foreach ($msg[$p] as $c => $l) { |
|
| 542 | + $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + $erreurs[$plug] = $msg[$p]; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | /** |
@@ -560,25 +560,25 @@ discard block |
||
| 560 | 560 | * - Liste des erreurs ou code HTML des erreurs |
| 561 | 561 | **/ |
| 562 | 562 | function plugin_donne_erreurs($raw = false, $raz = true) { |
| 563 | - if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 564 | - return $raw ? array() : ''; |
|
| 565 | - } |
|
| 566 | - $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 567 | - // Compat ancienne version |
|
| 568 | - if (!$list) { |
|
| 569 | - $list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 570 | - } elseif (!$raw) { |
|
| 571 | - foreach ($list as $plug => $msg) { |
|
| 572 | - $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug)) |
|
| 573 | - . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>"; |
|
| 574 | - } |
|
| 575 | - $list = "<ul>" . join("\n", $list) . "</ul>"; |
|
| 576 | - } |
|
| 577 | - if ($raz) { |
|
| 578 | - effacer_meta('plugin_erreur_activation'); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - return $list; |
|
| 563 | + if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 564 | + return $raw ? array() : ''; |
|
| 565 | + } |
|
| 566 | + $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 567 | + // Compat ancienne version |
|
| 568 | + if (!$list) { |
|
| 569 | + $list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 570 | + } elseif (!$raw) { |
|
| 571 | + foreach ($list as $plug => $msg) { |
|
| 572 | + $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug)) |
|
| 573 | + . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>"; |
|
| 574 | + } |
|
| 575 | + $list = "<ul>" . join("\n", $list) . "</ul>"; |
|
| 576 | + } |
|
| 577 | + if ($raz) { |
|
| 578 | + effacer_meta('plugin_erreur_activation'); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + return $list; |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | /** |
@@ -598,21 +598,21 @@ discard block |
||
| 598 | 598 | * |
| 599 | 599 | **/ |
| 600 | 600 | function plugin_necessite($n, $liste, $balise = 'necessite') { |
| 601 | - $msg = array(); |
|
| 602 | - foreach ($n as $need) { |
|
| 603 | - $id = strtoupper($need['nom']); |
|
| 604 | - $r = plugin_controler_necessite( |
|
| 605 | - $liste, |
|
| 606 | - $id, |
|
| 607 | - isset($need['compatibilite']) ? $need['compatibilite'] : '', |
|
| 608 | - $balise |
|
| 609 | - ); |
|
| 610 | - if ($r) { |
|
| 611 | - $msg[] = $r; |
|
| 612 | - } |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - return $msg; |
|
| 601 | + $msg = array(); |
|
| 602 | + foreach ($n as $need) { |
|
| 603 | + $id = strtoupper($need['nom']); |
|
| 604 | + $r = plugin_controler_necessite( |
|
| 605 | + $liste, |
|
| 606 | + $id, |
|
| 607 | + isset($need['compatibilite']) ? $need['compatibilite'] : '', |
|
| 608 | + $balise |
|
| 609 | + ); |
|
| 610 | + if ($r) { |
|
| 611 | + $msg[] = $r; |
|
| 612 | + } |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + return $msg; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -634,16 +634,16 @@ discard block |
||
| 634 | 634 | * Message d'erreur lorsque la dépendance est absente. |
| 635 | 635 | **/ |
| 636 | 636 | function plugin_controler_necessite($liste, $nom, $intervalle, $balise) { |
| 637 | - if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 638 | - return ''; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - return plugin_message_incompatibilite( |
|
| 642 | - $intervalle, |
|
| 643 | - (isset($liste[$nom]) ? $liste[$nom]['version'] : ""), |
|
| 644 | - $nom, |
|
| 645 | - $balise |
|
| 646 | - ); |
|
| 637 | + if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 638 | + return ''; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + return plugin_message_incompatibilite( |
|
| 642 | + $intervalle, |
|
| 643 | + (isset($liste[$nom]) ? $liste[$nom]['version'] : ""), |
|
| 644 | + $nom, |
|
| 645 | + $balise |
|
| 646 | + ); |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | /** |
@@ -660,68 +660,68 @@ discard block |
||
| 660 | 660 | */ |
| 661 | 661 | function plugin_message_incompatibilite($intervalle, $version, $nom, $balise) { |
| 662 | 662 | |
| 663 | - // prendre en compte les erreurs de dépendances à PHP |
|
| 664 | - // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 665 | - $type = 'plugin'; |
|
| 666 | - if ($nom === 'PHP') { |
|
| 667 | - $type = 'php'; |
|
| 668 | - } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 669 | - $type = 'extension_php'; |
|
| 670 | - list(,$nom) = explode(':', $nom, 2); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 674 | - $minimum = $regs[1]; |
|
| 675 | - $maximum = $regs[2]; |
|
| 676 | - |
|
| 677 | - $minimum_inclus = $intervalle{0} == "["; |
|
| 678 | - $maximum_inclus = substr($intervalle, -1) == "]"; |
|
| 679 | - |
|
| 680 | - if (strlen($minimum)) { |
|
| 681 | - if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 682 | - return _T("plugin_${balise}_${type}", array( |
|
| 683 | - 'plugin' => $nom, |
|
| 684 | - 'version' => ' ≥ ' . $minimum |
|
| 685 | - )); |
|
| 686 | - } |
|
| 687 | - if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 688 | - return _T("plugin_${balise}_${type}", array( |
|
| 689 | - 'plugin' => $nom, |
|
| 690 | - 'version' => ' > ' . $minimum |
|
| 691 | - )); |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - if (strlen($maximum)) { |
|
| 696 | - if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 697 | - return _T("plugin_${balise}_${type}", array( |
|
| 698 | - 'plugin' => $nom, |
|
| 699 | - 'version' => ' ≤ ' . $maximum |
|
| 700 | - )); |
|
| 701 | - } |
|
| 702 | - if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 703 | - return _T("plugin_${balise}_plugin", array( |
|
| 704 | - 'plugin' => $nom, |
|
| 705 | - 'version' => ' < ' . $maximum |
|
| 706 | - )); |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - // note : il ne peut pas y avoir d'erreur sur |
|
| 712 | - // - un 'utilise' sans version. |
|
| 713 | - // - un 'php' sans version. |
|
| 714 | - return _T("plugin_necessite_${type}_sans_version", array('plugin' => $nom)); |
|
| 663 | + // prendre en compte les erreurs de dépendances à PHP |
|
| 664 | + // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 665 | + $type = 'plugin'; |
|
| 666 | + if ($nom === 'PHP') { |
|
| 667 | + $type = 'php'; |
|
| 668 | + } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 669 | + $type = 'extension_php'; |
|
| 670 | + list(,$nom) = explode(':', $nom, 2); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 674 | + $minimum = $regs[1]; |
|
| 675 | + $maximum = $regs[2]; |
|
| 676 | + |
|
| 677 | + $minimum_inclus = $intervalle{0} == "["; |
|
| 678 | + $maximum_inclus = substr($intervalle, -1) == "]"; |
|
| 679 | + |
|
| 680 | + if (strlen($minimum)) { |
|
| 681 | + if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 682 | + return _T("plugin_${balise}_${type}", array( |
|
| 683 | + 'plugin' => $nom, |
|
| 684 | + 'version' => ' ≥ ' . $minimum |
|
| 685 | + )); |
|
| 686 | + } |
|
| 687 | + if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 688 | + return _T("plugin_${balise}_${type}", array( |
|
| 689 | + 'plugin' => $nom, |
|
| 690 | + 'version' => ' > ' . $minimum |
|
| 691 | + )); |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + if (strlen($maximum)) { |
|
| 696 | + if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 697 | + return _T("plugin_${balise}_${type}", array( |
|
| 698 | + 'plugin' => $nom, |
|
| 699 | + 'version' => ' ≤ ' . $maximum |
|
| 700 | + )); |
|
| 701 | + } |
|
| 702 | + if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 703 | + return _T("plugin_${balise}_plugin", array( |
|
| 704 | + 'plugin' => $nom, |
|
| 705 | + 'version' => ' < ' . $maximum |
|
| 706 | + )); |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + // note : il ne peut pas y avoir d'erreur sur |
|
| 712 | + // - un 'utilise' sans version. |
|
| 713 | + // - un 'php' sans version. |
|
| 714 | + return _T("plugin_necessite_${type}_sans_version", array('plugin' => $nom)); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | |
| 718 | 718 | function plugin_controler_lib($lib, $url) { |
| 719 | - /* Feature sortie du core, voir STP |
|
| 719 | + /* Feature sortie du core, voir STP |
|
| 720 | 720 | * if ($url) { |
| 721 | 721 | include_spip('inc/charger_plugin'); |
| 722 | 722 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 723 | 723 | }*/ |
| 724 | - return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>"; |
|
| 724 | + return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>"; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | * true si il y a eu des modifications sur la liste des plugins actifs, false sinon |
| 737 | 737 | **/ |
| 738 | 738 | function actualise_plugins_actifs($pipe_recherche = false) { |
| 739 | - return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 739 | + return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | |
@@ -763,113 +763,113 @@ discard block |
||
| 763 | 763 | **/ |
| 764 | 764 | function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') { |
| 765 | 765 | |
| 766 | - // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 767 | - $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 768 | - |
|
| 769 | - // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 770 | - if (!$cache and !spip_connect()) { |
|
| 771 | - return false; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - if ($operation != 'raz') { |
|
| 775 | - $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 776 | - $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 777 | - if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 778 | - $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 779 | - $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 780 | - $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 781 | - } |
|
| 782 | - // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 783 | - // on les reinjecte ici |
|
| 784 | - if (isset($GLOBALS['meta']['plugin_attente']) |
|
| 785 | - and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 786 | - ) { |
|
| 787 | - $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - if ($operation == 'ajoute') { |
|
| 791 | - $plugin = array_merge($plugin_valides, $plugin); |
|
| 792 | - } elseif ($operation == 'enleve') { |
|
| 793 | - $plugin = array_diff($plugin_valides, $plugin); |
|
| 794 | - } else { |
|
| 795 | - $plugin = $plugin_valides; |
|
| 796 | - } |
|
| 797 | - } |
|
| 798 | - $actifs_avant = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : ''; |
|
| 799 | - |
|
| 800 | - // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 801 | - if ($ajouter_dependances = charger_fonction("ajouter_dependances", "plugins", true)) { |
|
| 802 | - $plugin = $ajouter_dependances($plugin); |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - // recharger le xml des plugins a activer |
|
| 806 | - // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 807 | - // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 808 | - // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 809 | - // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 810 | - list($infos, $liste) = liste_plugin_valides($plugin, true); |
|
| 811 | - // trouver l'ordre d'activation |
|
| 812 | - list($plugin_valides, $ordre, $reste) = plugin_trier($infos, $liste); |
|
| 813 | - if ($reste) { |
|
| 814 | - plugins_erreurs($reste, $liste, $infos); |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - // Ignorer les plugins necessitant une lib absente |
|
| 818 | - // et preparer la meta d'entete Http |
|
| 819 | - $err = $msg = $header = array(); |
|
| 820 | - foreach ($plugin_valides as $p => $resume) { |
|
| 821 | - // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 822 | - if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 823 | - $header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : ""); |
|
| 824 | - } |
|
| 825 | - if ($resume['dir']) { |
|
| 826 | - foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 827 | - if (!find_in_path($l['nom'], 'lib/')) { |
|
| 828 | - $err[$p] = $resume; |
|
| 829 | - $msg[$p][] = $l; |
|
| 830 | - unset($plugin_valides[$p]); |
|
| 831 | - } |
|
| 832 | - } |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - if ($err) { |
|
| 836 | - plugins_erreurs($err, '', $infos, $msg); |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 840 | - effacer_meta('message_crash_plugins'); |
|
| 841 | - } |
|
| 842 | - ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 843 | - $liste = array_diff_key($liste, $plugin_valides); |
|
| 844 | - ecrire_meta('plugin_attente', serialize($liste)); |
|
| 845 | - $header = strtolower(implode(",", $header)); |
|
| 846 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 847 | - ecrire_fichier(_DIR_VAR . "config.txt", |
|
| 848 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header); |
|
| 849 | - } else { |
|
| 850 | - @unlink(_DIR_VAR . "config.txt"); |
|
| 851 | - } |
|
| 852 | - // generer charger_plugins_chemin.php |
|
| 853 | - plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 854 | - // generer les fichiers |
|
| 855 | - // - charger_plugins_options.php |
|
| 856 | - // - charger_plugins_fonctions.php |
|
| 857 | - plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 858 | - // charger les chemins des plugins et les fichiers d'options |
|
| 859 | - // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 860 | - plugins_amorcer_plugins_actifs(); |
|
| 861 | - // mise a jour de la matrice des pipelines |
|
| 862 | - $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 863 | - // generer le fichier _CACHE_PIPELINE |
|
| 864 | - pipeline_precompile($prepend_code); |
|
| 865 | - |
|
| 866 | - if (spip_connect()) { |
|
| 867 | - // lancer et initialiser les nouveaux crons ! |
|
| 868 | - include_spip('inc/genie'); |
|
| 869 | - genie_queue_watch_dist(); |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 766 | + // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 767 | + $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 768 | + |
|
| 769 | + // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 770 | + if (!$cache and !spip_connect()) { |
|
| 771 | + return false; |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + if ($operation != 'raz') { |
|
| 775 | + $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 776 | + $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 777 | + if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 778 | + $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 779 | + $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 780 | + $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 781 | + } |
|
| 782 | + // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 783 | + // on les reinjecte ici |
|
| 784 | + if (isset($GLOBALS['meta']['plugin_attente']) |
|
| 785 | + and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 786 | + ) { |
|
| 787 | + $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + if ($operation == 'ajoute') { |
|
| 791 | + $plugin = array_merge($plugin_valides, $plugin); |
|
| 792 | + } elseif ($operation == 'enleve') { |
|
| 793 | + $plugin = array_diff($plugin_valides, $plugin); |
|
| 794 | + } else { |
|
| 795 | + $plugin = $plugin_valides; |
|
| 796 | + } |
|
| 797 | + } |
|
| 798 | + $actifs_avant = isset($GLOBALS['meta']['plugin']) ? $GLOBALS['meta']['plugin'] : ''; |
|
| 799 | + |
|
| 800 | + // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 801 | + if ($ajouter_dependances = charger_fonction("ajouter_dependances", "plugins", true)) { |
|
| 802 | + $plugin = $ajouter_dependances($plugin); |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + // recharger le xml des plugins a activer |
|
| 806 | + // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 807 | + // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 808 | + // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 809 | + // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 810 | + list($infos, $liste) = liste_plugin_valides($plugin, true); |
|
| 811 | + // trouver l'ordre d'activation |
|
| 812 | + list($plugin_valides, $ordre, $reste) = plugin_trier($infos, $liste); |
|
| 813 | + if ($reste) { |
|
| 814 | + plugins_erreurs($reste, $liste, $infos); |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + // Ignorer les plugins necessitant une lib absente |
|
| 818 | + // et preparer la meta d'entete Http |
|
| 819 | + $err = $msg = $header = array(); |
|
| 820 | + foreach ($plugin_valides as $p => $resume) { |
|
| 821 | + // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 822 | + if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 823 | + $header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : ""); |
|
| 824 | + } |
|
| 825 | + if ($resume['dir']) { |
|
| 826 | + foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 827 | + if (!find_in_path($l['nom'], 'lib/')) { |
|
| 828 | + $err[$p] = $resume; |
|
| 829 | + $msg[$p][] = $l; |
|
| 830 | + unset($plugin_valides[$p]); |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + if ($err) { |
|
| 836 | + plugins_erreurs($err, '', $infos, $msg); |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 840 | + effacer_meta('message_crash_plugins'); |
|
| 841 | + } |
|
| 842 | + ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 843 | + $liste = array_diff_key($liste, $plugin_valides); |
|
| 844 | + ecrire_meta('plugin_attente', serialize($liste)); |
|
| 845 | + $header = strtolower(implode(",", $header)); |
|
| 846 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 847 | + ecrire_fichier(_DIR_VAR . "config.txt", |
|
| 848 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header); |
|
| 849 | + } else { |
|
| 850 | + @unlink(_DIR_VAR . "config.txt"); |
|
| 851 | + } |
|
| 852 | + // generer charger_plugins_chemin.php |
|
| 853 | + plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 854 | + // generer les fichiers |
|
| 855 | + // - charger_plugins_options.php |
|
| 856 | + // - charger_plugins_fonctions.php |
|
| 857 | + plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 858 | + // charger les chemins des plugins et les fichiers d'options |
|
| 859 | + // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 860 | + plugins_amorcer_plugins_actifs(); |
|
| 861 | + // mise a jour de la matrice des pipelines |
|
| 862 | + $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 863 | + // generer le fichier _CACHE_PIPELINE |
|
| 864 | + pipeline_precompile($prepend_code); |
|
| 865 | + |
|
| 866 | + if (spip_connect()) { |
|
| 867 | + // lancer et initialiser les nouveaux crons ! |
|
| 868 | + include_spip('inc/genie'); |
|
| 869 | + genie_queue_watch_dist(); |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 873 | 873 | } |
| 874 | 874 | |
| 875 | 875 | /** |
@@ -888,56 +888,56 @@ discard block |
||
| 888 | 888 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 889 | 889 | **/ |
| 890 | 890 | function plugins_precompile_chemin($plugin_valides, $ordre) { |
| 891 | - $chemins = array(); |
|
| 892 | - $contenu = ""; |
|
| 893 | - foreach ($ordre as $p => $info) { |
|
| 894 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 895 | - if (isset($plugin_valides[$p])) { |
|
| 896 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 897 | - $plug = $plugin_valides[$p]['dir']; |
|
| 898 | - // definir le plugin, donc le path avant l'include du fichier options |
|
| 899 | - // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 900 | - |
|
| 901 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 902 | - |
|
| 903 | - $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 904 | - if ( |
|
| 905 | - $prefix !== "SPIP" |
|
| 906 | - and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 907 | - ) { |
|
| 908 | - $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 909 | - foreach ($info['chemin'] as $chemin) { |
|
| 910 | - if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'], |
|
| 911 | - $GLOBALS['spip_version_branche'], 'spip') |
|
| 912 | - ) { |
|
| 913 | - $dir = $chemin['path']; |
|
| 914 | - if (strlen($dir) and $dir{0} == "/") { |
|
| 915 | - $dir = substr($dir, 1); |
|
| 916 | - } |
|
| 917 | - if (strlen($dir) and $dir == "./") { |
|
| 918 | - $dir = ''; |
|
| 919 | - } |
|
| 920 | - if (strlen($dir)) { |
|
| 921 | - $dir = rtrim($dir, '/') . '/'; |
|
| 922 | - } |
|
| 923 | - if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 924 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 925 | - } |
|
| 926 | - if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 927 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - } |
|
| 933 | - } |
|
| 934 | - if (count($chemins)) { |
|
| 935 | - $contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(" . implode(',', |
|
| 936 | - array_reverse($chemins['public'])) . ")));\n" |
|
| 937 | - . "else _chemin(implode(':',array(" . implode(',', array_reverse($chemins['prive'])) . ")));\n"; |
|
| 938 | - } |
|
| 939 | - |
|
| 940 | - ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 891 | + $chemins = array(); |
|
| 892 | + $contenu = ""; |
|
| 893 | + foreach ($ordre as $p => $info) { |
|
| 894 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 895 | + if (isset($plugin_valides[$p])) { |
|
| 896 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 897 | + $plug = $plugin_valides[$p]['dir']; |
|
| 898 | + // definir le plugin, donc le path avant l'include du fichier options |
|
| 899 | + // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 900 | + |
|
| 901 | + $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 902 | + |
|
| 903 | + $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 904 | + if ( |
|
| 905 | + $prefix !== "SPIP" |
|
| 906 | + and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 907 | + ) { |
|
| 908 | + $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 909 | + foreach ($info['chemin'] as $chemin) { |
|
| 910 | + if (!isset($chemin['version']) or plugin_version_compatible($chemin['version'], |
|
| 911 | + $GLOBALS['spip_version_branche'], 'spip') |
|
| 912 | + ) { |
|
| 913 | + $dir = $chemin['path']; |
|
| 914 | + if (strlen($dir) and $dir{0} == "/") { |
|
| 915 | + $dir = substr($dir, 1); |
|
| 916 | + } |
|
| 917 | + if (strlen($dir) and $dir == "./") { |
|
| 918 | + $dir = ''; |
|
| 919 | + } |
|
| 920 | + if (strlen($dir)) { |
|
| 921 | + $dir = rtrim($dir, '/') . '/'; |
|
| 922 | + } |
|
| 923 | + if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 924 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 925 | + } |
|
| 926 | + if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 927 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + } |
|
| 933 | + } |
|
| 934 | + if (count($chemins)) { |
|
| 935 | + $contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(" . implode(',', |
|
| 936 | + array_reverse($chemins['public'])) . ")));\n" |
|
| 937 | + . "else _chemin(implode(':',array(" . implode(',', array_reverse($chemins['prive'])) . ")));\n"; |
|
| 938 | + } |
|
| 939 | + |
|
| 940 | + ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | /** |
@@ -955,65 +955,65 @@ discard block |
||
| 955 | 955 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 956 | 956 | **/ |
| 957 | 957 | function plugins_precompile_xxxtions($plugin_valides, $ordre) { |
| 958 | - $contenu = array('options' => '', 'fonctions' => ''); |
|
| 959 | - $boutons = array(); |
|
| 960 | - $onglets = array(); |
|
| 961 | - $sign = ""; |
|
| 962 | - |
|
| 963 | - foreach ($ordre as $p => $info) { |
|
| 964 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 965 | - if (isset($plugin_valides[$p])) { |
|
| 966 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 967 | - $plug = $plugin_valides[$p]['dir']; |
|
| 968 | - $dir = constant($dir_type); |
|
| 969 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 970 | - if ($info['menu']) { |
|
| 971 | - $boutons = array_merge($boutons, $info['menu']); |
|
| 972 | - } |
|
| 973 | - if ($info['onglet']) { |
|
| 974 | - $onglets = array_merge($onglets, $info['onglet']); |
|
| 975 | - } |
|
| 976 | - foreach ($contenu as $charge => $v) { |
|
| 977 | - // si pas declare/detecte a la lecture du paquet.xml, |
|
| 978 | - // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 979 | - // donc ni sa relecture, ni sa detection |
|
| 980 | - if (!isset($info[$charge]) |
|
| 981 | - and $dir // exclure le cas du plugin "SPIP" |
|
| 982 | - and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 983 | - and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 984 | - ) { |
|
| 985 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) { |
|
| 986 | - $info[$charge] = array($file); |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - if (isset($info[$charge])) { |
|
| 990 | - $files = $info[$charge]; |
|
| 991 | - foreach ($files as $k => $file) { |
|
| 992 | - // on genere un if file_exists devant chaque include |
|
| 993 | - // pour pouvoir garder le meme niveau d'erreur general |
|
| 994 | - $file = trim($file); |
|
| 995 | - if (!is_readable("$dir$plug/$file") |
|
| 996 | - // uniquement pour les paquet.xml |
|
| 997 | - and file_exists("$dir$plug/paquet.xml") |
|
| 998 | - ) { |
|
| 999 | - unset($info[$charge][$k]); |
|
| 1000 | - } else { |
|
| 1001 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1002 | - $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1003 | - } |
|
| 1004 | - } |
|
| 1005 | - } |
|
| 1006 | - } |
|
| 1007 | - $sign .= md5(serialize($info)); |
|
| 1008 | - } |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1012 | - $contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons) |
|
| 1013 | - . plugin_ongletbouton("onglets_plugins", $onglets); |
|
| 1014 | - |
|
| 1015 | - ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1016 | - ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 958 | + $contenu = array('options' => '', 'fonctions' => ''); |
|
| 959 | + $boutons = array(); |
|
| 960 | + $onglets = array(); |
|
| 961 | + $sign = ""; |
|
| 962 | + |
|
| 963 | + foreach ($ordre as $p => $info) { |
|
| 964 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 965 | + if (isset($plugin_valides[$p])) { |
|
| 966 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 967 | + $plug = $plugin_valides[$p]['dir']; |
|
| 968 | + $dir = constant($dir_type); |
|
| 969 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 970 | + if ($info['menu']) { |
|
| 971 | + $boutons = array_merge($boutons, $info['menu']); |
|
| 972 | + } |
|
| 973 | + if ($info['onglet']) { |
|
| 974 | + $onglets = array_merge($onglets, $info['onglet']); |
|
| 975 | + } |
|
| 976 | + foreach ($contenu as $charge => $v) { |
|
| 977 | + // si pas declare/detecte a la lecture du paquet.xml, |
|
| 978 | + // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 979 | + // donc ni sa relecture, ni sa detection |
|
| 980 | + if (!isset($info[$charge]) |
|
| 981 | + and $dir // exclure le cas du plugin "SPIP" |
|
| 982 | + and strpos($dir, ":") === false // exclure le cas des procure: |
|
| 983 | + and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 984 | + ) { |
|
| 985 | + if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) { |
|
| 986 | + $info[$charge] = array($file); |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + if (isset($info[$charge])) { |
|
| 990 | + $files = $info[$charge]; |
|
| 991 | + foreach ($files as $k => $file) { |
|
| 992 | + // on genere un if file_exists devant chaque include |
|
| 993 | + // pour pouvoir garder le meme niveau d'erreur general |
|
| 994 | + $file = trim($file); |
|
| 995 | + if (!is_readable("$dir$plug/$file") |
|
| 996 | + // uniquement pour les paquet.xml |
|
| 997 | + and file_exists("$dir$plug/paquet.xml") |
|
| 998 | + ) { |
|
| 999 | + unset($info[$charge][$k]); |
|
| 1000 | + } else { |
|
| 1001 | + $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1002 | + $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1003 | + } |
|
| 1004 | + } |
|
| 1005 | + } |
|
| 1006 | + } |
|
| 1007 | + $sign .= md5(serialize($info)); |
|
| 1008 | + } |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1012 | + $contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons) |
|
| 1013 | + . plugin_ongletbouton("onglets_plugins", $onglets); |
|
| 1014 | + |
|
| 1015 | + ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1016 | + ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | 1019 | /** |
@@ -1032,24 +1032,24 @@ discard block |
||
| 1032 | 1032 | * @return string Code php |
| 1033 | 1033 | */ |
| 1034 | 1034 | function plugin_ongletbouton($nom, $val) { |
| 1035 | - if (!$val) { |
|
| 1036 | - $val = array(); |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - $val = serialize($val); |
|
| 1040 | - $md5 = md5($val); |
|
| 1041 | - |
|
| 1042 | - if (!defined("_UPDATED_$nom")) { |
|
| 1043 | - define("_UPDATED_$nom", $val); |
|
| 1044 | - define("_UPDATED_md5_$nom", $md5); |
|
| 1045 | - } |
|
| 1046 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1047 | - |
|
| 1048 | - return |
|
| 1049 | - "if (!function_exists('$nom')) {\n" |
|
| 1050 | - . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1051 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1052 | - . "}\n"; |
|
| 1035 | + if (!$val) { |
|
| 1036 | + $val = array(); |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + $val = serialize($val); |
|
| 1040 | + $md5 = md5($val); |
|
| 1041 | + |
|
| 1042 | + if (!defined("_UPDATED_$nom")) { |
|
| 1043 | + define("_UPDATED_$nom", $val); |
|
| 1044 | + define("_UPDATED_md5_$nom", $md5); |
|
| 1045 | + } |
|
| 1046 | + $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1047 | + |
|
| 1048 | + return |
|
| 1049 | + "if (!function_exists('$nom')) {\n" |
|
| 1050 | + . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1051 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1052 | + . "}\n"; |
|
| 1053 | 1053 | } |
| 1054 | 1054 | |
| 1055 | 1055 | /** |
@@ -1064,15 +1064,15 @@ discard block |
||
| 1064 | 1064 | **/ |
| 1065 | 1065 | function plugins_amorcer_plugins_actifs() { |
| 1066 | 1066 | |
| 1067 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1068 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1069 | - } |
|
| 1067 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1068 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1069 | + } |
|
| 1070 | 1070 | |
| 1071 | - if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1072 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 1073 | - } else { |
|
| 1074 | - spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT); |
|
| 1075 | - } |
|
| 1071 | + if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1072 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 1073 | + } else { |
|
| 1074 | + spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT); |
|
| 1075 | + } |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | /** |
@@ -1095,136 +1095,136 @@ discard block |
||
| 1095 | 1095 | * Couples (nom du pipeline => Code PHP à insérer au début du pipeline) |
| 1096 | 1096 | **/ |
| 1097 | 1097 | function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche) { |
| 1098 | - static $liste_pipe_manquants = array(); |
|
| 1099 | - if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1100 | - $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - $prepend_code = array(); |
|
| 1104 | - |
|
| 1105 | - foreach ($ordre as $p => $info) { |
|
| 1106 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1107 | - if (isset($plugin_valides[$p])) { |
|
| 1108 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1109 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1110 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1111 | - $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_"); |
|
| 1112 | - if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1113 | - foreach ($info['pipeline'] as $pipe) { |
|
| 1114 | - $nom = $pipe['nom']; |
|
| 1115 | - if (isset($pipe['action'])) { |
|
| 1116 | - $action = $pipe['action']; |
|
| 1117 | - } else { |
|
| 1118 | - $action = $nom; |
|
| 1119 | - } |
|
| 1120 | - $nomlower = strtolower($nom); |
|
| 1121 | - if ($nomlower != $nom |
|
| 1122 | - and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1123 | - and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1124 | - ) { |
|
| 1125 | - $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1126 | - unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1127 | - } |
|
| 1128 | - $nom = $nomlower; |
|
| 1129 | - // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1130 | - if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel |
|
| 1131 | - { |
|
| 1132 | - $GLOBALS['spip_pipeline'][$nom] = ""; |
|
| 1133 | - } |
|
| 1134 | - if ($action) { |
|
| 1135 | - if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) { |
|
| 1136 | - $GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1", |
|
| 1137 | - $GLOBALS['spip_pipeline'][$nom], 1); |
|
| 1138 | - } |
|
| 1139 | - if (isset($pipe['inclure'])) { |
|
| 1140 | - $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1141 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1142 | - } |
|
| 1143 | - } |
|
| 1144 | - } |
|
| 1145 | - } |
|
| 1146 | - if (isset($info['genie']) and count($info['genie'])) { |
|
| 1147 | - if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1148 | - $prepend_code['taches_generales_cron'] = ""; |
|
| 1149 | - } |
|
| 1150 | - foreach ($info['genie'] as $genie) { |
|
| 1151 | - $nom = $prefix . $genie['nom']; |
|
| 1152 | - $periode = max(60, intval($genie['periode'])); |
|
| 1153 | - if (charger_fonction($nom, "genie", true)) { |
|
| 1154 | - $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1155 | - } else { |
|
| 1156 | - spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1157 | - } |
|
| 1158 | - } |
|
| 1159 | - } |
|
| 1160 | - if (isset($info['style']) and count($info['style'])) { |
|
| 1161 | - if (!isset($prepend_code['insert_head_css'])) { |
|
| 1162 | - $prepend_code['insert_head_css'] = ""; |
|
| 1163 | - } |
|
| 1164 | - if (!isset($prepend_code['header_prive_css'])) { |
|
| 1165 | - $prepend_code['header_prive_css'] = ""; |
|
| 1166 | - } |
|
| 1167 | - foreach ($info['style'] as $style) { |
|
| 1168 | - if (isset($style['path']) and $style['path']) { |
|
| 1169 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1170 | - } else { |
|
| 1171 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1172 | - } |
|
| 1173 | - $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1174 | - if (isset($style['media']) and strlen($style['media'])) { |
|
| 1175 | - $code .= " media=\"" . addslashes($style['media']) . "\""; |
|
| 1176 | - } |
|
| 1177 | - $code .= "/>';\n"; |
|
| 1178 | - if ($style['type'] != 'prive') { |
|
| 1179 | - $prepend_code['insert_head_css'] .= $code; |
|
| 1180 | - } |
|
| 1181 | - if ($style['type'] != 'public') { |
|
| 1182 | - $prepend_code['header_prive_css'] .= $code; |
|
| 1183 | - } |
|
| 1184 | - } |
|
| 1185 | - } |
|
| 1186 | - if (!isset($prepend_code['insert_head'])) { |
|
| 1187 | - $prepend_code['insert_head'] = ""; |
|
| 1188 | - } |
|
| 1189 | - if (!isset($prepend_code['header_prive'])) { |
|
| 1190 | - $prepend_code['header_prive'] = ""; |
|
| 1191 | - } |
|
| 1192 | - if (isset($info['script']) and count($info['script'])) { |
|
| 1193 | - foreach ($info['script'] as $script) { |
|
| 1194 | - if (isset($script['path']) and $script['path']) { |
|
| 1195 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1196 | - } else { |
|
| 1197 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1198 | - } |
|
| 1199 | - $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1200 | - if ($script['type'] != 'prive') { |
|
| 1201 | - $prepend_code['insert_head'] .= $code; |
|
| 1202 | - } |
|
| 1203 | - if ($script['type'] != 'public') { |
|
| 1204 | - $prepend_code['header_prive'] .= $code; |
|
| 1205 | - } |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - } |
|
| 1209 | - } |
|
| 1210 | - |
|
| 1211 | - $prepend_code['insert_head'] = |
|
| 1212 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1213 | - . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1214 | - . $prepend_code['insert_head']; |
|
| 1215 | - $prepend_code['header_prive'] = |
|
| 1216 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1217 | - . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1218 | - . $prepend_code['header_prive']; |
|
| 1219 | - |
|
| 1220 | - // on ajoute les pipe qui ont ete recenses manquants |
|
| 1221 | - foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1222 | - if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1223 | - $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1224 | - } |
|
| 1225 | - } |
|
| 1226 | - |
|
| 1227 | - return $prepend_code; |
|
| 1098 | + static $liste_pipe_manquants = array(); |
|
| 1099 | + if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1100 | + $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + $prepend_code = array(); |
|
| 1104 | + |
|
| 1105 | + foreach ($ordre as $p => $info) { |
|
| 1106 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1107 | + if (isset($plugin_valides[$p])) { |
|
| 1108 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1109 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1110 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1111 | + $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_"); |
|
| 1112 | + if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1113 | + foreach ($info['pipeline'] as $pipe) { |
|
| 1114 | + $nom = $pipe['nom']; |
|
| 1115 | + if (isset($pipe['action'])) { |
|
| 1116 | + $action = $pipe['action']; |
|
| 1117 | + } else { |
|
| 1118 | + $action = $nom; |
|
| 1119 | + } |
|
| 1120 | + $nomlower = strtolower($nom); |
|
| 1121 | + if ($nomlower != $nom |
|
| 1122 | + and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1123 | + and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1124 | + ) { |
|
| 1125 | + $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1126 | + unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1127 | + } |
|
| 1128 | + $nom = $nomlower; |
|
| 1129 | + // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1130 | + if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel |
|
| 1131 | + { |
|
| 1132 | + $GLOBALS['spip_pipeline'][$nom] = ""; |
|
| 1133 | + } |
|
| 1134 | + if ($action) { |
|
| 1135 | + if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) { |
|
| 1136 | + $GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1", |
|
| 1137 | + $GLOBALS['spip_pipeline'][$nom], 1); |
|
| 1138 | + } |
|
| 1139 | + if (isset($pipe['inclure'])) { |
|
| 1140 | + $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1141 | + "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1142 | + } |
|
| 1143 | + } |
|
| 1144 | + } |
|
| 1145 | + } |
|
| 1146 | + if (isset($info['genie']) and count($info['genie'])) { |
|
| 1147 | + if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1148 | + $prepend_code['taches_generales_cron'] = ""; |
|
| 1149 | + } |
|
| 1150 | + foreach ($info['genie'] as $genie) { |
|
| 1151 | + $nom = $prefix . $genie['nom']; |
|
| 1152 | + $periode = max(60, intval($genie['periode'])); |
|
| 1153 | + if (charger_fonction($nom, "genie", true)) { |
|
| 1154 | + $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1155 | + } else { |
|
| 1156 | + spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1157 | + } |
|
| 1158 | + } |
|
| 1159 | + } |
|
| 1160 | + if (isset($info['style']) and count($info['style'])) { |
|
| 1161 | + if (!isset($prepend_code['insert_head_css'])) { |
|
| 1162 | + $prepend_code['insert_head_css'] = ""; |
|
| 1163 | + } |
|
| 1164 | + if (!isset($prepend_code['header_prive_css'])) { |
|
| 1165 | + $prepend_code['header_prive_css'] = ""; |
|
| 1166 | + } |
|
| 1167 | + foreach ($info['style'] as $style) { |
|
| 1168 | + if (isset($style['path']) and $style['path']) { |
|
| 1169 | + $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1170 | + } else { |
|
| 1171 | + $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1172 | + } |
|
| 1173 | + $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1174 | + if (isset($style['media']) and strlen($style['media'])) { |
|
| 1175 | + $code .= " media=\"" . addslashes($style['media']) . "\""; |
|
| 1176 | + } |
|
| 1177 | + $code .= "/>';\n"; |
|
| 1178 | + if ($style['type'] != 'prive') { |
|
| 1179 | + $prepend_code['insert_head_css'] .= $code; |
|
| 1180 | + } |
|
| 1181 | + if ($style['type'] != 'public') { |
|
| 1182 | + $prepend_code['header_prive_css'] .= $code; |
|
| 1183 | + } |
|
| 1184 | + } |
|
| 1185 | + } |
|
| 1186 | + if (!isset($prepend_code['insert_head'])) { |
|
| 1187 | + $prepend_code['insert_head'] = ""; |
|
| 1188 | + } |
|
| 1189 | + if (!isset($prepend_code['header_prive'])) { |
|
| 1190 | + $prepend_code['header_prive'] = ""; |
|
| 1191 | + } |
|
| 1192 | + if (isset($info['script']) and count($info['script'])) { |
|
| 1193 | + foreach ($info['script'] as $script) { |
|
| 1194 | + if (isset($script['path']) and $script['path']) { |
|
| 1195 | + $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1196 | + } else { |
|
| 1197 | + $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1198 | + } |
|
| 1199 | + $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1200 | + if ($script['type'] != 'prive') { |
|
| 1201 | + $prepend_code['insert_head'] .= $code; |
|
| 1202 | + } |
|
| 1203 | + if ($script['type'] != 'public') { |
|
| 1204 | + $prepend_code['header_prive'] .= $code; |
|
| 1205 | + } |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + } |
|
| 1209 | + } |
|
| 1210 | + |
|
| 1211 | + $prepend_code['insert_head'] = |
|
| 1212 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1213 | + . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1214 | + . $prepend_code['insert_head']; |
|
| 1215 | + $prepend_code['header_prive'] = |
|
| 1216 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1217 | + . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1218 | + . $prepend_code['header_prive']; |
|
| 1219 | + |
|
| 1220 | + // on ajoute les pipe qui ont ete recenses manquants |
|
| 1221 | + foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1222 | + if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1223 | + $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1224 | + } |
|
| 1225 | + } |
|
| 1226 | + |
|
| 1227 | + return $prepend_code; |
|
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | /** |
@@ -1251,44 +1251,44 @@ discard block |
||
| 1251 | 1251 | **/ |
| 1252 | 1252 | function pipeline_precompile($prepend_code = array()) { |
| 1253 | 1253 | |
| 1254 | - $content = ""; |
|
| 1255 | - foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1256 | - $s_inc = ""; |
|
| 1257 | - $s_call = ""; |
|
| 1258 | - $pipe = array_filter(explode('|', $pipeline)); |
|
| 1259 | - // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1260 | - foreach ($pipe as $fonc) { |
|
| 1261 | - $fonc = trim($fonc); |
|
| 1262 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1263 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1264 | - $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1265 | - $file = "'$file'"; |
|
| 1266 | - // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1267 | - if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums", $file, $regs)) { |
|
| 1268 | - $dir = $regs[1]; |
|
| 1269 | - $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1270 | - if (defined($root_dir)) { |
|
| 1271 | - $dir = $root_dir; |
|
| 1272 | - } |
|
| 1273 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1274 | - $file = str_replace("''.", "", $file); |
|
| 1275 | - $file = str_replace(constant($dir), '', $file); |
|
| 1276 | - } |
|
| 1277 | - $s_inc .= "include_once_check($file);\n"; |
|
| 1278 | - } |
|
| 1279 | - } |
|
| 1280 | - if (strlen($s_inc)) { |
|
| 1281 | - $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1282 | - } |
|
| 1283 | - $content .= "// Pipeline $action \n" |
|
| 1284 | - . "function execute_pipeline_$action(&\$val){\n" |
|
| 1285 | - . $s_inc |
|
| 1286 | - . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1287 | - . $s_call |
|
| 1288 | - . "return \$val;\n}\n"; |
|
| 1289 | - } |
|
| 1290 | - ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1291 | - clear_path_cache(); |
|
| 1254 | + $content = ""; |
|
| 1255 | + foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1256 | + $s_inc = ""; |
|
| 1257 | + $s_call = ""; |
|
| 1258 | + $pipe = array_filter(explode('|', $pipeline)); |
|
| 1259 | + // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1260 | + foreach ($pipe as $fonc) { |
|
| 1261 | + $fonc = trim($fonc); |
|
| 1262 | + $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1263 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1264 | + $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1265 | + $file = "'$file'"; |
|
| 1266 | + // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1267 | + if (preg_match(",(_(DIR|ROOT)_[A-Z_]+):,Ums", $file, $regs)) { |
|
| 1268 | + $dir = $regs[1]; |
|
| 1269 | + $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1270 | + if (defined($root_dir)) { |
|
| 1271 | + $dir = $root_dir; |
|
| 1272 | + } |
|
| 1273 | + $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1274 | + $file = str_replace("''.", "", $file); |
|
| 1275 | + $file = str_replace(constant($dir), '', $file); |
|
| 1276 | + } |
|
| 1277 | + $s_inc .= "include_once_check($file);\n"; |
|
| 1278 | + } |
|
| 1279 | + } |
|
| 1280 | + if (strlen($s_inc)) { |
|
| 1281 | + $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1282 | + } |
|
| 1283 | + $content .= "// Pipeline $action \n" |
|
| 1284 | + . "function execute_pipeline_$action(&\$val){\n" |
|
| 1285 | + . $s_inc |
|
| 1286 | + . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1287 | + . $s_call |
|
| 1288 | + . "return \$val;\n}\n"; |
|
| 1289 | + } |
|
| 1290 | + ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1291 | + clear_path_cache(); |
|
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | 1294 | |
@@ -1301,12 +1301,12 @@ discard block |
||
| 1301 | 1301 | * true si le plugin est actif, false sinon |
| 1302 | 1302 | **/ |
| 1303 | 1303 | function plugin_est_installe($plug_path) { |
| 1304 | - $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : array(); |
|
| 1305 | - if (!$plugin_installes) { |
|
| 1306 | - return false; |
|
| 1307 | - } |
|
| 1304 | + $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : array(); |
|
| 1305 | + if (!$plugin_installes) { |
|
| 1306 | + return false; |
|
| 1307 | + } |
|
| 1308 | 1308 | |
| 1309 | - return in_array($plug_path, $plugin_installes); |
|
| 1309 | + return in_array($plug_path, $plugin_installes); |
|
| 1310 | 1310 | } |
| 1311 | 1311 | |
| 1312 | 1312 | |
@@ -1319,37 +1319,37 @@ discard block |
||
| 1319 | 1319 | * @uses plugins_installer_dist() |
| 1320 | 1320 | **/ |
| 1321 | 1321 | function plugin_installes_meta() { |
| 1322 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1323 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 1324 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1325 | - } |
|
| 1326 | - |
|
| 1327 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1328 | - $meta_plug_installes = array(); |
|
| 1329 | - foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1330 | - if ($plug = $resume['dir']) { |
|
| 1331 | - $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1332 | - if ($infos) { |
|
| 1333 | - if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1334 | - $meta_plug_installes[] = $plug; |
|
| 1335 | - } |
|
| 1336 | - if (is_array($infos)) { |
|
| 1337 | - list($ok, $trace) = $infos['install_test']; |
|
| 1338 | - include_spip('inc/filtres_boites'); |
|
| 1339 | - echo "<div class='install-plugins svp_retour'>" |
|
| 1340 | - . boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))), |
|
| 1341 | - ($ok ? 'success' : 'error')) |
|
| 1342 | - . $trace |
|
| 1343 | - . "<div class='result'>" |
|
| 1344 | - . ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec")) |
|
| 1345 | - . "</div>" |
|
| 1346 | - . boite_fermer() |
|
| 1347 | - . "</div>"; |
|
| 1348 | - } |
|
| 1349 | - } |
|
| 1350 | - } |
|
| 1351 | - } |
|
| 1352 | - ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1322 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1323 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 1324 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1325 | + } |
|
| 1326 | + |
|
| 1327 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1328 | + $meta_plug_installes = array(); |
|
| 1329 | + foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1330 | + if ($plug = $resume['dir']) { |
|
| 1331 | + $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1332 | + if ($infos) { |
|
| 1333 | + if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1334 | + $meta_plug_installes[] = $plug; |
|
| 1335 | + } |
|
| 1336 | + if (is_array($infos)) { |
|
| 1337 | + list($ok, $trace) = $infos['install_test']; |
|
| 1338 | + include_spip('inc/filtres_boites'); |
|
| 1339 | + echo "<div class='install-plugins svp_retour'>" |
|
| 1340 | + . boite_ouvrir(_T('plugin_titre_installation', array('plugin' => typo($infos['nom']))), |
|
| 1341 | + ($ok ? 'success' : 'error')) |
|
| 1342 | + . $trace |
|
| 1343 | + . "<div class='result'>" |
|
| 1344 | + . ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T("plugin_info_upgrade_ok") : _T("plugin_info_install_ok")) : _T("avis_operation_echec")) |
|
| 1345 | + . "</div>" |
|
| 1346 | + . boite_fermer() |
|
| 1347 | + . "</div>"; |
|
| 1348 | + } |
|
| 1349 | + } |
|
| 1350 | + } |
|
| 1351 | + } |
|
| 1352 | + ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1353 | 1353 | } |
| 1354 | 1354 | |
| 1355 | 1355 | /** |
@@ -1363,29 +1363,29 @@ discard block |
||
| 1363 | 1363 | * Commentaire : code écrit en tout début de fichier, après la balise PHP ouvrante |
| 1364 | 1364 | **/ |
| 1365 | 1365 | function ecrire_fichier_php($nom, $contenu, $comment = '') { |
| 1366 | - if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1367 | - $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1371 | - // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1372 | - // si pas de modif on ne touche pas au fichier initial |
|
| 1373 | - if (file_exists($nom)) { |
|
| 1374 | - if (substr($nom, -4) == '.php') { |
|
| 1375 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1376 | - } |
|
| 1377 | - else { |
|
| 1378 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1379 | - } |
|
| 1380 | - file_put_contents($fichier_tmp, $contenu); |
|
| 1381 | - if(md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1382 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1383 | - @unlink($fichier_tmp); |
|
| 1384 | - return; |
|
| 1385 | - } |
|
| 1386 | - @unlink($fichier_tmp); |
|
| 1387 | - } |
|
| 1388 | - ecrire_fichier($nom, $contenu); |
|
| 1389 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1390 | - spip_clear_opcode_cache(realpath($nom)); |
|
| 1366 | + if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1367 | + $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1371 | + // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1372 | + // si pas de modif on ne touche pas au fichier initial |
|
| 1373 | + if (file_exists($nom)) { |
|
| 1374 | + if (substr($nom, -4) == '.php') { |
|
| 1375 | + $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1376 | + } |
|
| 1377 | + else { |
|
| 1378 | + $fichier_tmp = $nom . '.tmp'; |
|
| 1379 | + } |
|
| 1380 | + file_put_contents($fichier_tmp, $contenu); |
|
| 1381 | + if(md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1382 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1383 | + @unlink($fichier_tmp); |
|
| 1384 | + return; |
|
| 1385 | + } |
|
| 1386 | + @unlink($fichier_tmp); |
|
| 1387 | + } |
|
| 1388 | + ecrire_fichier($nom, $contenu); |
|
| 1389 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1390 | + spip_clear_opcode_cache(realpath($nom)); |
|
| 1391 | 1391 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
| 24 | -define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 24 | +define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS.'auto/'); |
|
| 25 | 25 | |
| 26 | 26 | #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins. |
| 27 | 27 | include_spip('plugins/installer'); |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | if ($dir) { |
| 352 | 352 | $dir .= "/"; |
| 353 | 353 | } |
| 354 | - $dir .= "procure:" . $procure['nom']; |
|
| 354 | + $dir .= "procure:".$procure['nom']; |
|
| 355 | 355 | |
| 356 | 356 | $procure['etat'] = '?'; |
| 357 | 357 | $procure['dir_type'] = $resume['dir_type']; |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | $plug = $resume['dir']; |
| 533 | 533 | $k = $infos[$dir_type][$plug]; |
| 534 | 534 | |
| 535 | - $plug = constant($dir_type) . $plug; |
|
| 535 | + $plug = constant($dir_type).$plug; |
|
| 536 | 536 | if (!isset($msg[$p])) { |
| 537 | 537 | if (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
| 538 | 538 | $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
@@ -569,10 +569,10 @@ discard block |
||
| 569 | 569 | $list = $raw ? array() : $GLOBALS['meta']['plugin_erreur_activation']; |
| 570 | 570 | } elseif (!$raw) { |
| 571 | 571 | foreach ($list as $plug => $msg) { |
| 572 | - $list[$plug] = "<li>" . _T('plugin_impossible_activer', array('plugin' => $plug)) |
|
| 573 | - . "<ul><li>" . implode("</li><li>", $msg) . "</li></ul></li>"; |
|
| 572 | + $list[$plug] = "<li>"._T('plugin_impossible_activer', array('plugin' => $plug)) |
|
| 573 | + . "<ul><li>".implode("</li><li>", $msg)."</li></ul></li>"; |
|
| 574 | 574 | } |
| 575 | - $list = "<ul>" . join("\n", $list) . "</ul>"; |
|
| 575 | + $list = "<ul>".join("\n", $list)."</ul>"; |
|
| 576 | 576 | } |
| 577 | 577 | if ($raz) { |
| 578 | 578 | effacer_meta('plugin_erreur_activation'); |
@@ -681,13 +681,13 @@ discard block |
||
| 681 | 681 | if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
| 682 | 682 | return _T("plugin_${balise}_${type}", array( |
| 683 | 683 | 'plugin' => $nom, |
| 684 | - 'version' => ' ≥ ' . $minimum |
|
| 684 | + 'version' => ' ≥ '.$minimum |
|
| 685 | 685 | )); |
| 686 | 686 | } |
| 687 | 687 | if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
| 688 | 688 | return _T("plugin_${balise}_${type}", array( |
| 689 | 689 | 'plugin' => $nom, |
| 690 | - 'version' => ' > ' . $minimum |
|
| 690 | + 'version' => ' > '.$minimum |
|
| 691 | 691 | )); |
| 692 | 692 | } |
| 693 | 693 | } |
@@ -696,13 +696,13 @@ discard block |
||
| 696 | 696 | if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
| 697 | 697 | return _T("plugin_${balise}_${type}", array( |
| 698 | 698 | 'plugin' => $nom, |
| 699 | - 'version' => ' ≤ ' . $maximum |
|
| 699 | + 'version' => ' ≤ '.$maximum |
|
| 700 | 700 | )); |
| 701 | 701 | } |
| 702 | 702 | if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
| 703 | 703 | return _T("plugin_${balise}_plugin", array( |
| 704 | 704 | 'plugin' => $nom, |
| 705 | - 'version' => ' < ' . $maximum |
|
| 705 | + 'version' => ' < '.$maximum |
|
| 706 | 706 | )); |
| 707 | 707 | } |
| 708 | 708 | } |
@@ -721,7 +721,7 @@ discard block |
||
| 721 | 721 | include_spip('inc/charger_plugin'); |
| 722 | 722 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 723 | 723 | }*/ |
| 724 | - return _T('plugin_necessite_lib', array('lib' => $lib)) . " <a href='$url'>$url</a>"; |
|
| 724 | + return _T('plugin_necessite_lib', array('lib' => $lib))." <a href='$url'>$url</a>"; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | foreach ($plugin_valides as $p => $resume) { |
| 821 | 821 | // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
| 822 | 822 | if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
| 823 | - $header[] = $p . ($resume['version'] ? "(" . $resume['version'] . ")" : ""); |
|
| 823 | + $header[] = $p.($resume['version'] ? "(".$resume['version'].")" : ""); |
|
| 824 | 824 | } |
| 825 | 825 | if ($resume['dir']) { |
| 826 | 826 | foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
@@ -844,10 +844,10 @@ discard block |
||
| 844 | 844 | ecrire_meta('plugin_attente', serialize($liste)); |
| 845 | 845 | $header = strtolower(implode(",", $header)); |
| 846 | 846 | if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
| 847 | - ecrire_fichier(_DIR_VAR . "config.txt", |
|
| 848 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP") . ' ' . $GLOBALS['spip_version_affichee'] . " @ www.spip.net + " . $header); |
|
| 847 | + ecrire_fichier(_DIR_VAR."config.txt", |
|
| 848 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : "Composed-By: SPIP").' '.$GLOBALS['spip_version_affichee']." @ www.spip.net + ".$header); |
|
| 849 | 849 | } else { |
| 850 | - @unlink(_DIR_VAR . "config.txt"); |
|
| 850 | + @unlink(_DIR_VAR."config.txt"); |
|
| 851 | 851 | } |
| 852 | 852 | // generer charger_plugins_chemin.php |
| 853 | 853 | plugins_precompile_chemin($plugin_valides, $ordre); |
@@ -898,7 +898,7 @@ discard block |
||
| 898 | 898 | // definir le plugin, donc le path avant l'include du fichier options |
| 899 | 899 | // permet de faire des include_spip pour attraper un inc_ du plugin |
| 900 | 900 | |
| 901 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 901 | + $dir = $dir_type.".'".$plug."/'"; |
|
| 902 | 902 | |
| 903 | 903 | $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
| 904 | 904 | if ( |
@@ -918,13 +918,13 @@ discard block |
||
| 918 | 918 | $dir = ''; |
| 919 | 919 | } |
| 920 | 920 | if (strlen($dir)) { |
| 921 | - $dir = rtrim($dir, '/') . '/'; |
|
| 921 | + $dir = rtrim($dir, '/').'/'; |
|
| 922 | 922 | } |
| 923 | 923 | if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
| 924 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 924 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : ""); |
|
| 925 | 925 | } |
| 926 | 926 | if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
| 927 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ""); |
|
| 927 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix".(strlen($dir) ? ".'$dir'" : ""); |
|
| 928 | 928 | } |
| 929 | 929 | } |
| 930 | 930 | } |
@@ -932,9 +932,9 @@ discard block |
||
| 932 | 932 | } |
| 933 | 933 | } |
| 934 | 934 | if (count($chemins)) { |
| 935 | - $contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(" . implode(',', |
|
| 936 | - array_reverse($chemins['public'])) . ")));\n" |
|
| 937 | - . "else _chemin(implode(':',array(" . implode(',', array_reverse($chemins['prive'])) . ")));\n"; |
|
| 935 | + $contenu .= "if (_DIR_RESTREINT) _chemin(implode(':',array(".implode(',', |
|
| 936 | + array_reverse($chemins['public'])).")));\n" |
|
| 937 | + . "else _chemin(implode(':',array(".implode(',', array_reverse($chemins['prive'])).")));\n"; |
|
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | and strpos($dir, ":") === false // exclure le cas des procure: |
| 983 | 983 | and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
| 984 | 984 | ) { |
| 985 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . "_" . $charge . ".php"))) { |
|
| 985 | + if (is_readable("$dir$plug/".($file = $info['prefix']."_".$charge.".php"))) { |
|
| 986 | 986 | $info[$charge] = array($file); |
| 987 | 987 | } |
| 988 | 988 | } |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | ) { |
| 999 | 999 | unset($info[$charge][$k]); |
| 1000 | 1000 | } else { |
| 1001 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1001 | + $_file = $root_dir_type.".'$plug/$file'"; |
|
| 1002 | 1002 | $contenu[$charge] .= "include_once_check($_file);\n"; |
| 1003 | 1003 | } |
| 1004 | 1004 | } |
@@ -1008,7 +1008,7 @@ discard block |
||
| 1008 | 1008 | } |
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1011 | + $contenu['options'] = "define('_PLUGINS_HASH','".md5($sign)."');\n".$contenu['options']; |
|
| 1012 | 1012 | $contenu['fonctions'] .= plugin_ongletbouton("boutons_plugins", $boutons) |
| 1013 | 1013 | . plugin_ongletbouton("onglets_plugins", $onglets); |
| 1014 | 1014 | |
@@ -1043,12 +1043,12 @@ discard block |
||
| 1043 | 1043 | define("_UPDATED_$nom", $val); |
| 1044 | 1044 | define("_UPDATED_md5_$nom", $md5); |
| 1045 | 1045 | } |
| 1046 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1046 | + $val = "unserialize('".str_replace("'", "\'", $val)."')"; |
|
| 1047 | 1047 | |
| 1048 | 1048 | return |
| 1049 | 1049 | "if (!function_exists('$nom')) {\n" |
| 1050 | 1050 | . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
| 1051 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1051 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'".$md5."';}\n" |
|
| 1052 | 1052 | . "}\n"; |
| 1053 | 1053 | } |
| 1054 | 1054 | |
@@ -1071,7 +1071,7 @@ discard block |
||
| 1071 | 1071 | if (@is_readable(_CACHE_PLUGINS_OPT)) { |
| 1072 | 1072 | include_once(_CACHE_PLUGINS_OPT); |
| 1073 | 1073 | } else { |
| 1074 | - spip_log("pipelines desactives: impossible de produire " . _CACHE_PLUGINS_OPT); |
|
| 1074 | + spip_log("pipelines desactives: impossible de produire "._CACHE_PLUGINS_OPT); |
|
| 1075 | 1075 | } |
| 1076 | 1076 | } |
| 1077 | 1077 | |
@@ -1108,7 +1108,7 @@ discard block |
||
| 1108 | 1108 | $dir_type = $plugin_valides[$p]['dir_type']; |
| 1109 | 1109 | $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
| 1110 | 1110 | $plug = $plugin_valides[$p]['dir']; |
| 1111 | - $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix'] . "_"); |
|
| 1111 | + $prefix = (($info['prefix'] == "spip") ? "" : $info['prefix']."_"); |
|
| 1112 | 1112 | if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
| 1113 | 1113 | foreach ($info['pipeline'] as $pipe) { |
| 1114 | 1114 | $nom = $pipe['nom']; |
@@ -1138,7 +1138,7 @@ discard block |
||
| 1138 | 1138 | } |
| 1139 | 1139 | if (isset($pipe['inclure'])) { |
| 1140 | 1140 | $GLOBALS['spip_matrice']["$prefix$action"] = |
| 1141 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1141 | + "$root_dir_type:$plug/".$pipe['inclure']; |
|
| 1142 | 1142 | } |
| 1143 | 1143 | } |
| 1144 | 1144 | } |
@@ -1148,7 +1148,7 @@ discard block |
||
| 1148 | 1148 | $prepend_code['taches_generales_cron'] = ""; |
| 1149 | 1149 | } |
| 1150 | 1150 | foreach ($info['genie'] as $genie) { |
| 1151 | - $nom = $prefix . $genie['nom']; |
|
| 1151 | + $nom = $prefix.$genie['nom']; |
|
| 1152 | 1152 | $periode = max(60, intval($genie['periode'])); |
| 1153 | 1153 | if (charger_fonction($nom, "genie", true)) { |
| 1154 | 1154 | $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
@@ -1166,13 +1166,13 @@ discard block |
||
| 1166 | 1166 | } |
| 1167 | 1167 | foreach ($info['style'] as $style) { |
| 1168 | 1168 | if (isset($style['path']) and $style['path']) { |
| 1169 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1169 | + $code = "if (\$f=timestamp(direction_css(find_in_path('".addslashes($style['path'])."')))) "; |
|
| 1170 | 1170 | } else { |
| 1171 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1171 | + $code = "if (\$f='".addslashes($style['url'])."') "; |
|
| 1172 | 1172 | } |
| 1173 | 1173 | $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
| 1174 | 1174 | if (isset($style['media']) and strlen($style['media'])) { |
| 1175 | - $code .= " media=\"" . addslashes($style['media']) . "\""; |
|
| 1175 | + $code .= " media=\"".addslashes($style['media'])."\""; |
|
| 1176 | 1176 | } |
| 1177 | 1177 | $code .= "/>';\n"; |
| 1178 | 1178 | if ($style['type'] != 'prive') { |
@@ -1192,9 +1192,9 @@ discard block |
||
| 1192 | 1192 | if (isset($info['script']) and count($info['script'])) { |
| 1193 | 1193 | foreach ($info['script'] as $script) { |
| 1194 | 1194 | if (isset($script['path']) and $script['path']) { |
| 1195 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1195 | + $code = "if (\$f=timestamp(find_in_path('".addslashes($script['path'])."'))) "; |
|
| 1196 | 1196 | } else { |
| 1197 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1197 | + $code = "if (\$f='".addslashes($script['url'])."') "; |
|
| 1198 | 1198 | } |
| 1199 | 1199 | $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
| 1200 | 1200 | if ($script['type'] != 'prive') { |
@@ -1259,7 +1259,7 @@ discard block |
||
| 1259 | 1259 | // Eclater le pipeline en filtres et appliquer chaque filtre |
| 1260 | 1260 | foreach ($pipe as $fonc) { |
| 1261 | 1261 | $fonc = trim($fonc); |
| 1262 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1262 | + $s_call .= '$val = minipipe(\''.$fonc.'\', $val);'."\n"; |
|
| 1263 | 1263 | if (isset($GLOBALS['spip_matrice'][$fonc])) { |
| 1264 | 1264 | $file = $GLOBALS['spip_matrice'][$fonc]; |
| 1265 | 1265 | $file = "'$file'"; |
@@ -1270,7 +1270,7 @@ discard block |
||
| 1270 | 1270 | if (defined($root_dir)) { |
| 1271 | 1271 | $dir = $root_dir; |
| 1272 | 1272 | } |
| 1273 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1273 | + $file = str_replace($regs[0], "'.".$dir.".'", $file); |
|
| 1274 | 1274 | $file = str_replace("''.", "", $file); |
| 1275 | 1275 | $file = str_replace(constant($dir), '', $file); |
| 1276 | 1276 | } |
@@ -1283,7 +1283,7 @@ discard block |
||
| 1283 | 1283 | $content .= "// Pipeline $action \n" |
| 1284 | 1284 | . "function execute_pipeline_$action(&\$val){\n" |
| 1285 | 1285 | . $s_inc |
| 1286 | - . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1286 | + . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action])."\n" : '') |
|
| 1287 | 1287 | . $s_call |
| 1288 | 1288 | . "return \$val;\n}\n"; |
| 1289 | 1289 | } |
@@ -1367,18 +1367,18 @@ discard block |
||
| 1367 | 1367 | $GLOBALS['fichier_php_compile_recent'] = 0; |
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1370 | + $contenu = '<'.'?php'."\n".$comment."\nif (defined('_ECRIRE_INC_VERSION')) {\n".$contenu."}\n?".'>'; |
|
| 1371 | 1371 | // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
| 1372 | 1372 | // si pas de modif on ne touche pas au fichier initial |
| 1373 | 1373 | if (file_exists($nom)) { |
| 1374 | 1374 | if (substr($nom, -4) == '.php') { |
| 1375 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1375 | + $fichier_tmp = substr($nom, 0, -4).'.tmp.php'; |
|
| 1376 | 1376 | } |
| 1377 | 1377 | else { |
| 1378 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1378 | + $fichier_tmp = $nom.'.tmp'; |
|
| 1379 | 1379 | } |
| 1380 | 1380 | file_put_contents($fichier_tmp, $contenu); |
| 1381 | - if(md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1381 | + if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1382 | 1382 | $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
| 1383 | 1383 | @unlink($fichier_tmp); |
| 1384 | 1384 | return; |
@@ -1127,10 +1127,12 @@ discard block |
||
| 1127 | 1127 | } |
| 1128 | 1128 | $nom = $nomlower; |
| 1129 | 1129 | // une action vide est une declaration qui ne doit pas etre compilee ! |
| 1130 | - if (!isset($GLOBALS['spip_pipeline'][$nom])) // creer le pipeline eventuel |
|
| 1130 | + if (!isset($GLOBALS['spip_pipeline'][$nom])) { |
|
| 1131 | + // creer le pipeline eventuel |
|
| 1131 | 1132 | { |
| 1132 | 1133 | $GLOBALS['spip_pipeline'][$nom] = ""; |
| 1133 | 1134 | } |
| 1135 | + } |
|
| 1134 | 1136 | if ($action) { |
| 1135 | 1137 | if (strpos($GLOBALS['spip_pipeline'][$nom], "|$prefix$action") === false) { |
| 1136 | 1138 | $GLOBALS['spip_pipeline'][$nom] = preg_replace(",(\|\||$),", "|$prefix$action\\1", |
@@ -1373,8 +1375,7 @@ discard block |
||
| 1373 | 1375 | if (file_exists($nom)) { |
| 1374 | 1376 | if (substr($nom, -4) == '.php') { |
| 1375 | 1377 | $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
| 1376 | - } |
|
| 1377 | - else { |
|
| 1378 | + } else { |
|
| 1378 | 1379 | $fichier_tmp = $nom . '.tmp'; |
| 1379 | 1380 | } |
| 1380 | 1381 | file_put_contents($fichier_tmp, $contenu); |