@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Fonctions |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -29,29 +29,29 @@ discard block |
||
| 29 | 29 | * @param bool $left |
| 30 | 30 | */ |
| 31 | 31 | function critere_compteur_articles_filtres_dist($idb, &$boucles, $crit, $left = false) { |
| 32 | - $boucle = &$boucles[$idb]; |
|
| 32 | + $boucle = &$boucles[$idb]; |
|
| 33 | 33 | |
| 34 | - $_statut = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 34 | + $_statut = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 35 | 35 | |
| 36 | - $not = ''; |
|
| 37 | - if ($crit->not) { |
|
| 38 | - $not = ", 'NOT'"; |
|
| 39 | - } |
|
| 40 | - $boucle->from['LAA'] = 'spip_auteurs_liens'; |
|
| 41 | - $boucle->from_type['LAA'] = 'left'; |
|
| 42 | - $boucle->join['LAA'] = array("'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''"); |
|
| 36 | + $not = ''; |
|
| 37 | + if ($crit->not) { |
|
| 38 | + $not = ", 'NOT'"; |
|
| 39 | + } |
|
| 40 | + $boucle->from['LAA'] = 'spip_auteurs_liens'; |
|
| 41 | + $boucle->from_type['LAA'] = 'left'; |
|
| 42 | + $boucle->join['LAA'] = array("'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''"); |
|
| 43 | 43 | |
| 44 | - $boucle->from['articles'] = 'spip_articles'; |
|
| 45 | - $boucle->from_type['articles'] = 'left'; |
|
| 46 | - $boucle->join['articles'] = array( |
|
| 47 | - "'LAA'", |
|
| 48 | - "'id_article'", |
|
| 49 | - "'id_objet'", |
|
| 50 | - "'(articles.statut IS NULL OR '.sql_in('articles.statut',_q($_statut)$not).')'" |
|
| 51 | - ); |
|
| 44 | + $boucle->from['articles'] = 'spip_articles'; |
|
| 45 | + $boucle->from_type['articles'] = 'left'; |
|
| 46 | + $boucle->join['articles'] = array( |
|
| 47 | + "'LAA'", |
|
| 48 | + "'id_article'", |
|
| 49 | + "'id_objet'", |
|
| 50 | + "'(articles.statut IS NULL OR '.sql_in('articles.statut',_q($_statut)$not).')'" |
|
| 51 | + ); |
|
| 52 | 52 | |
| 53 | - $boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles'; |
|
| 54 | - $boucle->group[] = 'auteurs.id_auteur'; |
|
| 53 | + $boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles'; |
|
| 54 | + $boucle->group[] = 'auteurs.id_auteur'; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * Pile complétée par le code à générer |
| 70 | 70 | */ |
| 71 | 71 | function balise_COMPTEUR_ARTICLES_dist($p) { |
| 72 | - return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres'); |
|
| 72 | + return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -85,43 +85,43 @@ discard block |
||
| 85 | 85 | * @return string |
| 86 | 86 | */ |
| 87 | 87 | function afficher_initiale($url, $initiale, $compteur, $debut, $pas) { |
| 88 | - static $memo = null; |
|
| 89 | - static $res = []; |
|
| 90 | - $out = ''; |
|
| 91 | - if (!$memo |
|
| 92 | - or (!$initiale and !$url) |
|
| 93 | - or ($initiale !== $memo['initiale']) |
|
| 94 | - ) { |
|
| 95 | - $newcompt = intval(floor(($compteur - 1) / $pas) * $pas); |
|
| 96 | - // si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien |
|
| 97 | - if (!$initiale and !$url and !$memo['compteur']) { |
|
| 98 | - $memo = null; |
|
| 99 | - } |
|
| 100 | - if ($memo) { |
|
| 101 | - $on = (($memo['compteur'] <= $debut) |
|
| 102 | - and ( |
|
| 103 | - $newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur']) |
|
| 104 | - )); |
|
| 105 | - $res[] = lien_ou_expose($memo['url'], $memo['initiale'], $on, 'lien_pagination'); |
|
| 106 | - } |
|
| 107 | - if ($initiale) { |
|
| 108 | - $memo = array( |
|
| 109 | - 'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0, |
|
| 110 | - 'initiale' => $initiale, |
|
| 111 | - 'url' => parametre_url($url, 'i', $initiale), |
|
| 112 | - 'compteur' => $newcompt |
|
| 113 | - ); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - if (!$initiale and !$url) { |
|
| 117 | - if (count($res) > 1) { |
|
| 118 | - $out = implode(' ', $res); |
|
| 119 | - } |
|
| 120 | - $memo = null; |
|
| 121 | - $res = []; |
|
| 122 | - } |
|
| 88 | + static $memo = null; |
|
| 89 | + static $res = []; |
|
| 90 | + $out = ''; |
|
| 91 | + if (!$memo |
|
| 92 | + or (!$initiale and !$url) |
|
| 93 | + or ($initiale !== $memo['initiale']) |
|
| 94 | + ) { |
|
| 95 | + $newcompt = intval(floor(($compteur - 1) / $pas) * $pas); |
|
| 96 | + // si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien |
|
| 97 | + if (!$initiale and !$url and !$memo['compteur']) { |
|
| 98 | + $memo = null; |
|
| 99 | + } |
|
| 100 | + if ($memo) { |
|
| 101 | + $on = (($memo['compteur'] <= $debut) |
|
| 102 | + and ( |
|
| 103 | + $newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur']) |
|
| 104 | + )); |
|
| 105 | + $res[] = lien_ou_expose($memo['url'], $memo['initiale'], $on, 'lien_pagination'); |
|
| 106 | + } |
|
| 107 | + if ($initiale) { |
|
| 108 | + $memo = array( |
|
| 109 | + 'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0, |
|
| 110 | + 'initiale' => $initiale, |
|
| 111 | + 'url' => parametre_url($url, 'i', $initiale), |
|
| 112 | + 'compteur' => $newcompt |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + if (!$initiale and !$url) { |
|
| 117 | + if (count($res) > 1) { |
|
| 118 | + $out = implode(' ', $res); |
|
| 119 | + } |
|
| 120 | + $memo = null; |
|
| 121 | + $res = []; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - return $out; |
|
| 124 | + return $out; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -140,23 +140,23 @@ discard block |
||
| 140 | 140 | * @return string |
| 141 | 141 | */ |
| 142 | 142 | function auteur_lien_messagerie($id_auteur, $en_ligne, $statut, $imessage, $email = '') { |
| 143 | - static $time = null; |
|
| 144 | - if (!in_array($statut, array('0minirezo', '1comite'))) { |
|
| 145 | - return ''; |
|
| 146 | - } |
|
| 143 | + static $time = null; |
|
| 144 | + if (!in_array($statut, array('0minirezo', '1comite'))) { |
|
| 145 | + return ''; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - if (is_null($time)) { |
|
| 149 | - $time = time(); |
|
| 150 | - } |
|
| 151 | - $parti = (($time - strtotime($en_ligne)) > 15 * 60); |
|
| 148 | + if (is_null($time)) { |
|
| 149 | + $time = time(); |
|
| 150 | + } |
|
| 151 | + $parti = (($time - strtotime($en_ligne)) > 15 * 60); |
|
| 152 | 152 | |
| 153 | - if ($imessage != 'non' and !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ? |
|
| 154 | - and $GLOBALS['meta']['messagerie_agenda'] != 'non' |
|
| 155 | - ) { |
|
| 156 | - return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self()); |
|
| 157 | - } elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) { |
|
| 158 | - return 'mailto:' . $email; |
|
| 159 | - } else { |
|
| 160 | - return ''; |
|
| 161 | - } |
|
| 153 | + if ($imessage != 'non' and !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ? |
|
| 154 | + and $GLOBALS['meta']['messagerie_agenda'] != 'non' |
|
| 155 | + ) { |
|
| 156 | + return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self()); |
|
| 157 | + } elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) { |
|
| 158 | + return 'mailto:' . $email; |
|
| 159 | + } else { |
|
| 160 | + return ''; |
|
| 161 | + } |
|
| 162 | 162 | } |
@@ -73,16 +73,16 @@ discard block |
||
| 73 | 73 | protected $_lcount = 19; |
| 74 | 74 | protected $_vcount = 21; |
| 75 | 75 | protected $_tcount = 28; |
| 76 | - protected $_ncount = 588; // _vcount * _tcount |
|
| 76 | + protected $_ncount = 588; // _vcount * _tcount |
|
| 77 | 77 | protected $_scount = 11172; // _lcount * _tcount * _vcount |
| 78 | 78 | protected $_error = false; |
| 79 | 79 | protected static $_mb_string_overload = null; |
| 80 | 80 | // See {@link set_paramter()} for details of how to change the following |
| 81 | 81 | // settings from within your script / application |
| 82 | - protected $_api_encoding = 'utf8'; // Default input charset is UTF-8 |
|
| 83 | - protected $_allow_overlong = false; // Overlong UTF-8 encodings are forbidden |
|
| 84 | - protected $_strict_mode = false; // Behave strict or not |
|
| 85 | - protected $_idn_version = 2003; // Can be either 2003 (old, default) or 2008 |
|
| 82 | + protected $_api_encoding = 'utf8'; // Default input charset is UTF-8 |
|
| 83 | + protected $_allow_overlong = false; // Overlong UTF-8 encodings are forbidden |
|
| 84 | + protected $_strict_mode = false; // Behave strict or not |
|
| 85 | + protected $_idn_version = 2003; // Can be either 2003 (old, default) or 2008 |
|
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * the constructor |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | $this->_api_encoding = $v; |
| 141 | 141 | break; |
| 142 | 142 | default: |
| 143 | - $this->_error('Set Parameter: Unknown parameter ' . $v . ' for option ' . $k); |
|
| 143 | + $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k); |
|
| 144 | 144 | return false; |
| 145 | 145 | } |
| 146 | 146 | break; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | if (in_array($v, array('2003', '2008'))) { |
| 155 | 155 | $this->_idn_version = $v; |
| 156 | 156 | } else { |
| 157 | - $this->_error('Set Parameter: Unknown parameter ' . $v . ' for option ' . $k); |
|
| 157 | + $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k); |
|
| 158 | 158 | } |
| 159 | 159 | break; |
| 160 | 160 | case 'encode_german_sz': // Deprecated |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | break; |
| 167 | 167 | default: |
| 168 | - $this->_error('Set Parameter: Unknown option ' . $k); |
|
| 168 | + $this->_error('Set Parameter: Unknown option '.$k); |
|
| 169 | 169 | return false; |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | case 'ucs4_array': |
| 189 | 189 | break; |
| 190 | 190 | default: |
| 191 | - $this->_error('Unknown encoding ' . $one_time_encoding); |
|
| 191 | + $this->_error('Unknown encoding '.$one_time_encoding); |
|
| 192 | 192 | return false; |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | list ($email_pref, $input) = explode('@', $input, 2); |
| 207 | 207 | $arr = explode('.', $input); |
| 208 | 208 | foreach ($arr as $k => $v) { |
| 209 | - if (preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) { |
|
| 209 | + if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) { |
|
| 210 | 210 | $conv = $this->_decode($v); |
| 211 | 211 | if ($conv) { |
| 212 | 212 | $arr[$k] = $conv; |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $input = join('.', $arr); |
| 217 | 217 | $arr = explode('.', $email_pref); |
| 218 | 218 | foreach ($arr as $k => $v) { |
| 219 | - if (preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $v)) { |
|
| 219 | + if (preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $v)) { |
|
| 220 | 220 | $conv = $this->_decode($v); |
| 221 | 221 | if ($conv) { |
| 222 | 222 | $arr[$k] = $conv; |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | $email_pref = join('.', $arr); |
| 227 | - $return = $email_pref . '@' . $input; |
|
| 227 | + $return = $email_pref.'@'.$input; |
|
| 228 | 228 | } elseif (preg_match('![:\./]!', $input)) { // Or a complete domain name (with or without paths / parameters) |
| 229 | 229 | // No no in strict mode |
| 230 | 230 | if ($this->_strict_mode) { |
@@ -241,13 +241,13 @@ discard block |
||
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | $parsed['host'] = join('.', $arr); |
| 244 | - $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'] . (strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')). |
|
| 245 | - (empty($parsed['user']) ? '' : $parsed['user'] . (empty($parsed['pass']) ? '' : ':' . $parsed['pass']) . '@'). |
|
| 244 | + $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')). |
|
| 245 | + (empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@'). |
|
| 246 | 246 | $parsed['host']. |
| 247 | - (empty($parsed['port']) ? '' : ':' . $parsed['port']). |
|
| 247 | + (empty($parsed['port']) ? '' : ':'.$parsed['port']). |
|
| 248 | 248 | (empty($parsed['path']) ? '' : $parsed['path']). |
| 249 | - (empty($parsed['query']) ? '' : '?' . $parsed['query']). |
|
| 250 | - (empty($parsed['fragment']) ? '' : '#' . $parsed['fragment']); |
|
| 249 | + (empty($parsed['query']) ? '' : '?'.$parsed['query']). |
|
| 250 | + (empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']); |
|
| 251 | 251 | } else { // parse_url seems to have failed, try without it |
| 252 | 252 | $arr = explode('.', $input); |
| 253 | 253 | foreach ($arr as $k => $v) { |
@@ -265,8 +265,8 @@ discard block |
||
| 265 | 265 | // The output is UTF-8 by default, other output formats need conversion here |
| 266 | 266 | // If one time encoding is given, use this, else the objects property |
| 267 | 267 | switch (($one_time_encoding) ? $one_time_encoding : $this->_api_encoding) { |
| 268 | - case 'utf8': return $return; // break; |
|
| 269 | - case 'ucs4_string': return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return)); // break; |
|
| 268 | + case 'utf8' : return $return; // break; |
|
| 269 | + case 'ucs4_string': return $this->_ucs4_to_ucs4_string($this->_utf8_to_ucs4($return)); // break; |
|
| 270 | 270 | case 'ucs4_array': return $this->_utf8_to_ucs4($return); // break; |
| 271 | 271 | default: $this->_error('Unsupported output format'); return false; |
| 272 | 272 | } |
@@ -283,15 +283,14 @@ discard block |
||
| 283 | 283 | // Forcing conversion of input to UCS4 array |
| 284 | 284 | // If one time encoding is given, use this, else the objects property |
| 285 | 285 | switch ($one_time_encoding ? $one_time_encoding : $this->_api_encoding) { |
| 286 | - case 'utf8': |
|
| 287 | - $decoded = $this->_utf8_to_ucs4($decoded); |
|
| 286 | + case 'utf8' : $decoded = $this->_utf8_to_ucs4($decoded); |
|
| 288 | 287 | break; |
| 289 | 288 | case 'ucs4_string': |
| 290 | 289 | $decoded = $this->_ucs4_string_to_ucs4($decoded); |
| 291 | 290 | case 'ucs4_array': |
| 292 | 291 | break; |
| 293 | 292 | default: |
| 294 | - $this->_error('Unsupported input format: ' . ($one_time_encoding ? $one_time_encoding : $this->_api_encoding)); |
|
| 293 | + $this->_error('Unsupported input format: '.($one_time_encoding ? $one_time_encoding : $this->_api_encoding)); |
|
| 295 | 294 | return false; |
| 296 | 295 | } |
| 297 | 296 | |
@@ -380,13 +379,13 @@ discard block |
||
| 380 | 379 | } |
| 381 | 380 | } |
| 382 | 381 | $parsed['host'] = join('.', $arr); |
| 383 | - $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'] . (strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')). |
|
| 384 | - (empty($parsed['user']) ? '' : $parsed['user'] . (empty($parsed['pass']) ? '' : ':' . $parsed['pass']) . '@'). |
|
| 382 | + $return = (empty($parsed['scheme']) ? '' : $parsed['scheme'].(strtolower($parsed['scheme']) == 'mailto' ? ':' : '://')). |
|
| 383 | + (empty($parsed['user']) ? '' : $parsed['user'].(empty($parsed['pass']) ? '' : ':'.$parsed['pass']).'@'). |
|
| 385 | 384 | $parsed['host']. |
| 386 | - (empty($parsed['port']) ? '' : ':' . $parsed['port']). |
|
| 385 | + (empty($parsed['port']) ? '' : ':'.$parsed['port']). |
|
| 387 | 386 | (empty($parsed['path']) ? '' : $parsed['path']). |
| 388 | - (empty($parsed['query']) ? '' : '?' . $parsed['query']). |
|
| 389 | - (empty($parsed['fragment']) ? '' : '#' . $parsed['fragment']); |
|
| 387 | + (empty($parsed['query']) ? '' : '?'.$parsed['query']). |
|
| 388 | + (empty($parsed['fragment']) ? '' : '#'.$parsed['fragment']); |
|
| 390 | 389 | return $return; |
| 391 | 390 | } |
| 392 | 391 | |
@@ -409,11 +408,11 @@ discard block |
||
| 409 | 408 | { |
| 410 | 409 | $decoded = array(); |
| 411 | 410 | // find the Punycode prefix |
| 412 | - if (!preg_match('!^' . preg_quote($this->_punycode_prefix, '!') . '!', $encoded)) { |
|
| 411 | + if (!preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $encoded)) { |
|
| 413 | 412 | $this->_error('This is not a punycode string'); |
| 414 | 413 | return false; |
| 415 | 414 | } |
| 416 | - $encode_test = preg_replace('!^' . preg_quote($this->_punycode_prefix, '!') . '!', '', $encoded); |
|
| 415 | + $encode_test = preg_replace('!^'.preg_quote($this->_punycode_prefix, '!').'!', '', $encoded); |
|
| 417 | 416 | // If nothing left after removing the prefix, it is hopeless |
| 418 | 417 | if (!$encode_test) { |
| 419 | 418 | $this->_error('The given encoded string was empty'); |
@@ -439,8 +438,7 @@ discard block |
||
| 439 | 438 | for ($old_idx = $idx, $w = 1, $k = $this->_base; 1; $k += $this->_base) { |
| 440 | 439 | $digit = $this->_decode_digit($encoded[$enco_idx++]); |
| 441 | 440 | $idx += $digit * $w; |
| 442 | - $t = ($k <= $bias) ? $this->_tmin : |
|
| 443 | - (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias)); |
|
| 441 | + $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias)); |
|
| 444 | 442 | if ($digit < $t) { |
| 445 | 443 | break; |
| 446 | 444 | } |
@@ -513,7 +511,7 @@ discard block |
||
| 513 | 511 | return $encoded; // All codepoints were basic ones |
| 514 | 512 | } |
| 515 | 513 | // Start with the prefix; copy it to output |
| 516 | - $encoded = $this->_punycode_prefix . $encoded; |
|
| 514 | + $encoded = $this->_punycode_prefix.$encoded; |
|
| 517 | 515 | // If we have basic code points in output, add an hyphen to the end |
| 518 | 516 | if ($codecount) { |
| 519 | 517 | $encoded .= '-'; |
@@ -540,8 +538,7 @@ discard block |
||
| 540 | 538 | $delta++; |
| 541 | 539 | } elseif ($decoded[$i] == $cur_code) { |
| 542 | 540 | for ($q = $delta, $k = $this->_base; 1; $k += $this->_base) { |
| 543 | - $t = ($k <= $bias) ? $this->_tmin : |
|
| 544 | - (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias); |
|
| 541 | + $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias); |
|
| 545 | 542 | if ($q < $t) { |
| 546 | 543 | break; |
| 547 | 544 | } |
@@ -628,12 +625,12 @@ discard block |
||
| 628 | 625 | } |
| 629 | 626 | // Try to find prohibited input |
| 630 | 627 | if (in_array($v, self::$NP['prohibit']) || in_array($v, self::$NP['general_prohibited'])) { |
| 631 | - $this->_error('NAMEPREP: Prohibited input U+' . sprintf('%08X', $v)); |
|
| 628 | + $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v)); |
|
| 632 | 629 | return false; |
| 633 | 630 | } |
| 634 | 631 | foreach (self::$NP['prohibit_ranges'] as $range) { |
| 635 | 632 | if ($range[0] <= $v && $v <= $range[1]) { |
| 636 | - $this->_error('NAMEPREP: Prohibited input U+' . sprintf('%08X', $v)); |
|
| 633 | + $this->_error('NAMEPREP: Prohibited input U+'.sprintf('%08X', $v)); |
|
| 637 | 634 | return false; |
| 638 | 635 | } |
| 639 | 636 | } |
@@ -869,7 +866,7 @@ discard block |
||
| 869 | 866 | $output[$out_len] = $v; |
| 870 | 867 | ++$out_len; |
| 871 | 868 | if ('add' == $mode) { |
| 872 | - $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k); |
|
| 869 | + $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k); |
|
| 873 | 870 | return false; |
| 874 | 871 | } |
| 875 | 872 | continue; |
@@ -894,7 +891,7 @@ discard block |
||
| 894 | 891 | $next_byte = 4; |
| 895 | 892 | $v = ($v - 252) << 30; |
| 896 | 893 | } else { |
| 897 | - $this->_error('This might be UTF-8, but I don\'t understand it at byte ' . $k); |
|
| 894 | + $this->_error('This might be UTF-8, but I don\'t understand it at byte '.$k); |
|
| 898 | 895 | return false; |
| 899 | 896 | } |
| 900 | 897 | if ('add' == $mode) { |
@@ -907,7 +904,7 @@ discard block |
||
| 907 | 904 | if (!$this->_allow_overlong && $test == 'range') { |
| 908 | 905 | $test = 'none'; |
| 909 | 906 | if (($v < 0xA0 && $start_byte == 0xE0) || ($v < 0x90 && $start_byte == 0xF0) || ($v > 0x8F && $start_byte == 0xF4)) { |
| 910 | - $this->_error('Bogus UTF-8 character detected (out of legal range) at byte ' . $k); |
|
| 907 | + $this->_error('Bogus UTF-8 character detected (out of legal range) at byte '.$k); |
|
| 911 | 908 | return false; |
| 912 | 909 | } |
| 913 | 910 | } |
@@ -916,7 +913,7 @@ discard block |
||
| 916 | 913 | $output[($out_len - 1)] += $v; |
| 917 | 914 | --$next_byte; |
| 918 | 915 | } else { |
| 919 | - $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte ' . $k); |
|
| 916 | + $this->_error('Conversion from UTF-8 to UCS-4 failed: malformed input at byte '.$k); |
|
| 920 | 917 | return false; |
| 921 | 918 | } |
| 922 | 919 | if ($next_byte < 0) { |
@@ -940,13 +937,13 @@ discard block |
||
| 940 | 937 | if ($v < 128) { // 7bit are transferred literally |
| 941 | 938 | $output .= chr($v); |
| 942 | 939 | } elseif ($v < (1 << 11)) { // 2 bytes |
| 943 | - $output .= chr(192 + ($v >> 6)) . chr(128 + ($v & 63)); |
|
| 940 | + $output .= chr(192 + ($v >> 6)).chr(128 + ($v & 63)); |
|
| 944 | 941 | } elseif ($v < (1 << 16)) { // 3 bytes |
| 945 | - $output .= chr(224 + ($v >> 12)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63)); |
|
| 942 | + $output .= chr(224 + ($v >> 12)).chr(128 + (($v >> 6) & 63)).chr(128 + ($v & 63)); |
|
| 946 | 943 | } elseif ($v < (1 << 21)) { // 4 bytes |
| 947 | - $output .= chr(240 + ($v >> 18)) . chr(128 + (($v >> 12) & 63)) . chr(128 + (($v >> 6) & 63)) . chr(128 + ($v & 63)); |
|
| 944 | + $output .= chr(240 + ($v >> 18)).chr(128 + (($v >> 12) & 63)).chr(128 + (($v >> 6) & 63)).chr(128 + ($v & 63)); |
|
| 948 | 945 | } else { |
| 949 | - $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte ' . $k); |
|
| 946 | + $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k); |
|
| 950 | 947 | return false; |
| 951 | 948 | } |
| 952 | 949 | } |
@@ -965,7 +962,7 @@ discard block |
||
| 965 | 962 | // Take array values and split output to 4 bytes per value |
| 966 | 963 | // The bit mask is 255, which reads &11111111 |
| 967 | 964 | foreach ($input as $v) { |
| 968 | - $output .= chr(($v >> 24) & 255) . chr(($v >> 16) & 255) . chr(($v >> 8) & 255) . chr($v & 255); |
|
| 965 | + $output .= chr(($v >> 24) & 255).chr(($v >> 16) & 255).chr(($v >> 8) & 255).chr($v & 255); |
|
| 969 | 966 | } |
| 970 | 967 | return $output; |
| 971 | 968 | } |
@@ -995,7 +992,7 @@ discard block |
||
| 995 | 992 | $out_len++; |
| 996 | 993 | $output[$out_len] = 0; |
| 997 | 994 | } |
| 998 | - $output[$out_len] += ord($input[$i]) << (8 * (3 - ($i % 4) ) ); |
|
| 995 | + $output[$out_len] += ord($input[$i]) << (8 * (3 - ($i % 4))); |
|
| 999 | 996 | } |
| 1000 | 997 | return $output; |
| 1001 | 998 | } |
@@ -20,11 +20,11 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | if (!defined('_MYSQL_NOPLANES')) { |
| 27 | - define('_MYSQL_NOPLANES', true); |
|
| 27 | + define('_MYSQL_NOPLANES', true); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -41,104 +41,104 @@ discard block |
||
| 41 | 41 | * - tableau décrivant la connexion sinon |
| 42 | 42 | */ |
| 43 | 43 | function req_mysql_dist($host, $port, $login, $pass, $db = '', $prefixe = '') { |
| 44 | - if (!extension_loaded('mysqli')) { |
|
| 45 | - return false; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 49 | - if ( |
|
| 50 | - $port and !is_numeric($socket = $port) |
|
| 51 | - and (!$host or $host=='localhost')) { |
|
| 52 | - $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 53 | - } |
|
| 54 | - elseif ($port) { |
|
| 55 | - $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | - } |
|
| 57 | - else { |
|
| 58 | - $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - if (!$link) { |
|
| 62 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 63 | - |
|
| 64 | - return false; |
|
| 65 | - } |
|
| 66 | - $last = ''; |
|
| 67 | - if (!$db) { |
|
| 68 | - $ok = $link; |
|
| 69 | - $db = 'spip'; |
|
| 70 | - } else { |
|
| 71 | - $ok = mysqli_select_db($link, $db); |
|
| 72 | - if (defined('_MYSQL_SET_SQL_MODE') |
|
| 73 | - or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 74 | - ) { |
|
| 75 | - mysqli_query($link, $last = "set sql_mode=''"); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle" : 'impossible'), |
|
| 80 | - _LOG_DEBUG); |
|
| 81 | - |
|
| 82 | - return !$ok ? false : array( |
|
| 83 | - 'db' => $db, |
|
| 84 | - 'last' => $last, |
|
| 85 | - 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 86 | - 'link' => $link, |
|
| 87 | - 'total_requetes' => 0, |
|
| 88 | - ); |
|
| 44 | + if (!extension_loaded('mysqli')) { |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 49 | + if ( |
|
| 50 | + $port and !is_numeric($socket = $port) |
|
| 51 | + and (!$host or $host=='localhost')) { |
|
| 52 | + $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 53 | + } |
|
| 54 | + elseif ($port) { |
|
| 55 | + $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | + } |
|
| 57 | + else { |
|
| 58 | + $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + if (!$link) { |
|
| 62 | + spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 63 | + |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 66 | + $last = ''; |
|
| 67 | + if (!$db) { |
|
| 68 | + $ok = $link; |
|
| 69 | + $db = 'spip'; |
|
| 70 | + } else { |
|
| 71 | + $ok = mysqli_select_db($link, $db); |
|
| 72 | + if (defined('_MYSQL_SET_SQL_MODE') |
|
| 73 | + or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 74 | + ) { |
|
| 75 | + mysqli_query($link, $last = "set sql_mode=''"); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle" : 'impossible'), |
|
| 80 | + _LOG_DEBUG); |
|
| 81 | + |
|
| 82 | + return !$ok ? false : array( |
|
| 83 | + 'db' => $db, |
|
| 84 | + 'last' => $last, |
|
| 85 | + 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 86 | + 'link' => $link, |
|
| 87 | + 'total_requetes' => 0, |
|
| 88 | + ); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | $GLOBALS['spip_mysql_functions_1'] = array( |
| 93 | - 'alter' => 'spip_mysql_alter', |
|
| 94 | - 'count' => 'spip_mysql_count', |
|
| 95 | - 'countsel' => 'spip_mysql_countsel', |
|
| 96 | - 'create' => 'spip_mysql_create', |
|
| 97 | - 'create_base' => 'spip_mysql_create_base', |
|
| 98 | - 'create_view' => 'spip_mysql_create_view', |
|
| 99 | - 'date_proche' => 'spip_mysql_date_proche', |
|
| 100 | - 'delete' => 'spip_mysql_delete', |
|
| 101 | - 'drop_table' => 'spip_mysql_drop_table', |
|
| 102 | - 'drop_view' => 'spip_mysql_drop_view', |
|
| 103 | - 'errno' => 'spip_mysql_errno', |
|
| 104 | - 'error' => 'spip_mysql_error', |
|
| 105 | - 'explain' => 'spip_mysql_explain', |
|
| 106 | - 'fetch' => 'spip_mysql_fetch', |
|
| 107 | - 'seek' => 'spip_mysql_seek', |
|
| 108 | - 'free' => 'spip_mysql_free', |
|
| 109 | - 'hex' => 'spip_mysql_hex', |
|
| 110 | - 'in' => 'spip_mysql_in', |
|
| 111 | - 'insert' => 'spip_mysql_insert', |
|
| 112 | - 'insertq' => 'spip_mysql_insertq', |
|
| 113 | - 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 114 | - 'listdbs' => 'spip_mysql_listdbs', |
|
| 115 | - 'multi' => 'spip_mysql_multi', |
|
| 116 | - 'optimize' => 'spip_mysql_optimize', |
|
| 117 | - 'query' => 'spip_mysql_query', |
|
| 118 | - 'quote' => 'spip_mysql_quote', |
|
| 119 | - 'replace' => 'spip_mysql_replace', |
|
| 120 | - 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 121 | - 'repair' => 'spip_mysql_repair', |
|
| 122 | - 'select' => 'spip_mysql_select', |
|
| 123 | - 'selectdb' => 'spip_mysql_selectdb', |
|
| 124 | - 'set_charset' => 'spip_mysql_set_charset', |
|
| 125 | - 'get_charset' => 'spip_mysql_get_charset', |
|
| 126 | - 'showbase' => 'spip_mysql_showbase', |
|
| 127 | - 'showtable' => 'spip_mysql_showtable', |
|
| 128 | - 'update' => 'spip_mysql_update', |
|
| 129 | - 'updateq' => 'spip_mysql_updateq', |
|
| 130 | - |
|
| 131 | - // association de chaque nom http d'un charset aux couples MySQL |
|
| 132 | - 'charsets' => array( |
|
| 133 | - 'cp1250' => array('charset' => 'cp1250', 'collation' => 'cp1250_general_ci'), |
|
| 134 | - 'cp1251' => array('charset' => 'cp1251', 'collation' => 'cp1251_general_ci'), |
|
| 135 | - 'cp1256' => array('charset' => 'cp1256', 'collation' => 'cp1256_general_ci'), |
|
| 136 | - 'iso-8859-1' => array('charset' => 'latin1', 'collation' => 'latin1_swedish_ci'), |
|
| 93 | + 'alter' => 'spip_mysql_alter', |
|
| 94 | + 'count' => 'spip_mysql_count', |
|
| 95 | + 'countsel' => 'spip_mysql_countsel', |
|
| 96 | + 'create' => 'spip_mysql_create', |
|
| 97 | + 'create_base' => 'spip_mysql_create_base', |
|
| 98 | + 'create_view' => 'spip_mysql_create_view', |
|
| 99 | + 'date_proche' => 'spip_mysql_date_proche', |
|
| 100 | + 'delete' => 'spip_mysql_delete', |
|
| 101 | + 'drop_table' => 'spip_mysql_drop_table', |
|
| 102 | + 'drop_view' => 'spip_mysql_drop_view', |
|
| 103 | + 'errno' => 'spip_mysql_errno', |
|
| 104 | + 'error' => 'spip_mysql_error', |
|
| 105 | + 'explain' => 'spip_mysql_explain', |
|
| 106 | + 'fetch' => 'spip_mysql_fetch', |
|
| 107 | + 'seek' => 'spip_mysql_seek', |
|
| 108 | + 'free' => 'spip_mysql_free', |
|
| 109 | + 'hex' => 'spip_mysql_hex', |
|
| 110 | + 'in' => 'spip_mysql_in', |
|
| 111 | + 'insert' => 'spip_mysql_insert', |
|
| 112 | + 'insertq' => 'spip_mysql_insertq', |
|
| 113 | + 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 114 | + 'listdbs' => 'spip_mysql_listdbs', |
|
| 115 | + 'multi' => 'spip_mysql_multi', |
|
| 116 | + 'optimize' => 'spip_mysql_optimize', |
|
| 117 | + 'query' => 'spip_mysql_query', |
|
| 118 | + 'quote' => 'spip_mysql_quote', |
|
| 119 | + 'replace' => 'spip_mysql_replace', |
|
| 120 | + 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 121 | + 'repair' => 'spip_mysql_repair', |
|
| 122 | + 'select' => 'spip_mysql_select', |
|
| 123 | + 'selectdb' => 'spip_mysql_selectdb', |
|
| 124 | + 'set_charset' => 'spip_mysql_set_charset', |
|
| 125 | + 'get_charset' => 'spip_mysql_get_charset', |
|
| 126 | + 'showbase' => 'spip_mysql_showbase', |
|
| 127 | + 'showtable' => 'spip_mysql_showtable', |
|
| 128 | + 'update' => 'spip_mysql_update', |
|
| 129 | + 'updateq' => 'spip_mysql_updateq', |
|
| 130 | + |
|
| 131 | + // association de chaque nom http d'un charset aux couples MySQL |
|
| 132 | + 'charsets' => array( |
|
| 133 | + 'cp1250' => array('charset' => 'cp1250', 'collation' => 'cp1250_general_ci'), |
|
| 134 | + 'cp1251' => array('charset' => 'cp1251', 'collation' => 'cp1251_general_ci'), |
|
| 135 | + 'cp1256' => array('charset' => 'cp1256', 'collation' => 'cp1256_general_ci'), |
|
| 136 | + 'iso-8859-1' => array('charset' => 'latin1', 'collation' => 'latin1_swedish_ci'), |
|
| 137 | 137 | //'iso-8859-6'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 138 | - 'iso-8859-9' => array('charset' => 'latin5', 'collation' => 'latin5_turkish_ci'), |
|
| 138 | + 'iso-8859-9' => array('charset' => 'latin5', 'collation' => 'latin5_turkish_ci'), |
|
| 139 | 139 | //'iso-8859-15'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 140 | - 'utf-8' => array('charset' => 'utf8', 'collation' => 'utf8_general_ci') |
|
| 141 | - ) |
|
| 140 | + 'utf-8' => array('charset' => 'utf8', 'collation' => 'utf8_general_ci') |
|
| 141 | + ) |
|
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | 144 | |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | * @return Object Information de connexion pour mysqli |
| 150 | 150 | */ |
| 151 | 151 | function _mysql_link($serveur = '') { |
| 152 | - $link = &$GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 152 | + $link = &$GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 153 | 153 | |
| 154 | - return $link; |
|
| 154 | + return $link; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | * @return resource Ressource de résultats pour fetch() |
| 165 | 165 | */ |
| 166 | 166 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 167 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 168 | - spip_log("changement de charset sql : " . "SET NAMES " . _q($charset), _LOG_DEBUG); |
|
| 167 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 168 | + spip_log("changement de charset sql : " . "SET NAMES " . _q($charset), _LOG_DEBUG); |
|
| 169 | 169 | |
| 170 | - return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES " . _q($charset)); |
|
| 170 | + return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES " . _q($charset)); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | * @return array Description du charset (son nom est dans 'charset') |
| 181 | 181 | */ |
| 182 | 182 | function spip_mysql_get_charset($charset = array(), $serveur = '', $requeter = true) { |
| 183 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 184 | - $connexion['last'] = $c = "SHOW CHARACTER SET" |
|
| 185 | - . (!$charset ? '' : (" LIKE " . _q($charset['charset']))); |
|
| 183 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 184 | + $connexion['last'] = $c = "SHOW CHARACTER SET" |
|
| 185 | + . (!$charset ? '' : (" LIKE " . _q($charset['charset']))); |
|
| 186 | 186 | |
| 187 | - return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 187 | + return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @return Resource Ressource pour fetch() |
| 200 | 200 | **/ |
| 201 | 201 | function spip_query_db($query, $serveur = '', $requeter = true) { |
| 202 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 202 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -216,61 +216,61 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | function spip_mysql_query($query, $serveur = '', $requeter = true) { |
| 218 | 218 | |
| 219 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 220 | - $prefixe = $connexion['prefixe']; |
|
| 221 | - $link = $connexion['link']; |
|
| 222 | - $db = $connexion['db']; |
|
| 223 | - |
|
| 224 | - $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 225 | - |
|
| 226 | - // renvoyer la requete inerte si demandee |
|
| 227 | - if (!$requeter) { |
|
| 228 | - return $query; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - if (isset($_GET['var_profile'])) { |
|
| 232 | - include_spip('public/tracer'); |
|
| 233 | - $t = trace_query_start(); |
|
| 234 | - } else { |
|
| 235 | - $t = 0; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - $connexion['last'] = $query; |
|
| 239 | - $connexion['total_requetes']++; |
|
| 240 | - |
|
| 241 | - // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 242 | - $debug = ''; |
|
| 243 | - if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 244 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 245 | - list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | - $debug .= "BOUCLE$id @ " . (isset($infos[0]) ? $infos[0] : '') . " | "; |
|
| 247 | - } |
|
| 248 | - $debug .= $_SERVER['REQUEST_URI'] . ' + ' . $GLOBALS['ip']; |
|
| 249 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $r = mysqli_query($link, $query . $debug); |
|
| 253 | - |
|
| 254 | - //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 255 | - if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 256 | - if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 257 | - //Fermer la connexion defaillante |
|
| 258 | - mysqli_close($connexion['link']); |
|
| 259 | - unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 260 | - //Relancer une connexion vierge |
|
| 261 | - spip_connect($serveur); |
|
| 262 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 263 | - $link = $connexion['link']; |
|
| 264 | - //On retente au cas où |
|
| 265 | - $r = mysqli_query($link, $query . $debug); |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Log de l'erreur eventuelle |
|
| 270 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 271 | - $e .= spip_mysql_error($query, $serveur); |
|
| 272 | - } // et du fautif |
|
| 273 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 219 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 220 | + $prefixe = $connexion['prefixe']; |
|
| 221 | + $link = $connexion['link']; |
|
| 222 | + $db = $connexion['db']; |
|
| 223 | + |
|
| 224 | + $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 225 | + |
|
| 226 | + // renvoyer la requete inerte si demandee |
|
| 227 | + if (!$requeter) { |
|
| 228 | + return $query; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + if (isset($_GET['var_profile'])) { |
|
| 232 | + include_spip('public/tracer'); |
|
| 233 | + $t = trace_query_start(); |
|
| 234 | + } else { |
|
| 235 | + $t = 0; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + $connexion['last'] = $query; |
|
| 239 | + $connexion['total_requetes']++; |
|
| 240 | + |
|
| 241 | + // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 242 | + $debug = ''; |
|
| 243 | + if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 244 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 245 | + list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | + $debug .= "BOUCLE$id @ " . (isset($infos[0]) ? $infos[0] : '') . " | "; |
|
| 247 | + } |
|
| 248 | + $debug .= $_SERVER['REQUEST_URI'] . ' + ' . $GLOBALS['ip']; |
|
| 249 | + $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $r = mysqli_query($link, $query . $debug); |
|
| 253 | + |
|
| 254 | + //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 255 | + if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 256 | + if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 257 | + //Fermer la connexion defaillante |
|
| 258 | + mysqli_close($connexion['link']); |
|
| 259 | + unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 260 | + //Relancer une connexion vierge |
|
| 261 | + spip_connect($serveur); |
|
| 262 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 263 | + $link = $connexion['link']; |
|
| 264 | + //On retente au cas où |
|
| 265 | + $r = mysqli_query($link, $query . $debug); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Log de l'erreur eventuelle |
|
| 270 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 271 | + $e .= spip_mysql_error($query, $serveur); |
|
| 272 | + } // et du fautif |
|
| 273 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -285,12 +285,12 @@ discard block |
||
| 285 | 285 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 286 | 286 | */ |
| 287 | 287 | function spip_mysql_alter($query, $serveur = '', $requeter = true) { |
| 288 | - // ici on supprime les ` entourant le nom de table pour permettre |
|
| 289 | - // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 290 | - // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 291 | - $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
|
| 288 | + // ici on supprime les ` entourant le nom de table pour permettre |
|
| 289 | + // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 290 | + // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 291 | + $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
|
| 292 | 292 | |
| 293 | - return spip_mysql_query("ALTER " . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 293 | + return spip_mysql_query("ALTER " . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -303,9 +303,9 @@ discard block |
||
| 303 | 303 | * @return bool Toujours true |
| 304 | 304 | */ |
| 305 | 305 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 306 | - spip_mysql_query("OPTIMIZE TABLE " . $table); |
|
| 306 | + spip_mysql_query("OPTIMIZE TABLE " . $table); |
|
| 307 | 307 | |
| 308 | - return true; |
|
| 308 | + return true; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
@@ -318,18 +318,18 @@ discard block |
||
| 318 | 318 | * @return array Tableau de l'explication |
| 319 | 319 | */ |
| 320 | 320 | function spip_mysql_explain($query, $serveur = '', $requeter = true) { |
| 321 | - if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 322 | - return array(); |
|
| 323 | - } |
|
| 324 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 325 | - $prefixe = $connexion['prefixe']; |
|
| 326 | - $link = $connexion['link']; |
|
| 327 | - $db = $connexion['db']; |
|
| 328 | - |
|
| 329 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 330 | - $r = mysqli_query($link, $query); |
|
| 331 | - |
|
| 332 | - return spip_mysql_fetch($r, null, $serveur); |
|
| 321 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 322 | + return array(); |
|
| 323 | + } |
|
| 324 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 325 | + $prefixe = $connexion['prefixe']; |
|
| 326 | + $link = $connexion['link']; |
|
| 327 | + $db = $connexion['db']; |
|
| 328 | + |
|
| 329 | + $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 330 | + $r = mysqli_query($link, $query); |
|
| 331 | + |
|
| 332 | + return spip_mysql_fetch($r, null, $serveur); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -358,35 +358,35 @@ discard block |
||
| 358 | 358 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 359 | 359 | */ |
| 360 | 360 | function spip_mysql_select( |
| 361 | - $select, |
|
| 362 | - $from, |
|
| 363 | - $where = '', |
|
| 364 | - $groupby = '', |
|
| 365 | - $orderby = '', |
|
| 366 | - $limit = '', |
|
| 367 | - $having = '', |
|
| 368 | - $serveur = '', |
|
| 369 | - $requeter = true |
|
| 361 | + $select, |
|
| 362 | + $from, |
|
| 363 | + $where = '', |
|
| 364 | + $groupby = '', |
|
| 365 | + $orderby = '', |
|
| 366 | + $limit = '', |
|
| 367 | + $having = '', |
|
| 368 | + $serveur = '', |
|
| 369 | + $requeter = true |
|
| 370 | 370 | ) { |
| 371 | 371 | |
| 372 | 372 | |
| 373 | - $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 374 | - $query = |
|
| 375 | - calculer_mysql_expression('SELECT', $select, ', ') |
|
| 376 | - . calculer_mysql_expression('FROM', $from, ', ') |
|
| 377 | - . calculer_mysql_expression('WHERE', $where) |
|
| 378 | - . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 379 | - . calculer_mysql_expression('HAVING', $having) |
|
| 380 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 381 | - . ($limit ? "\nLIMIT $limit" : ''); |
|
| 373 | + $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 374 | + $query = |
|
| 375 | + calculer_mysql_expression('SELECT', $select, ', ') |
|
| 376 | + . calculer_mysql_expression('FROM', $from, ', ') |
|
| 377 | + . calculer_mysql_expression('WHERE', $where) |
|
| 378 | + . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 379 | + . calculer_mysql_expression('HAVING', $having) |
|
| 380 | + . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 381 | + . ($limit ? "\nLIMIT $limit" : ''); |
|
| 382 | 382 | |
| 383 | - // renvoyer la requete inerte si demandee |
|
| 384 | - if ($requeter === false) { |
|
| 385 | - return $query; |
|
| 386 | - } |
|
| 387 | - $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 383 | + // renvoyer la requete inerte si demandee |
|
| 384 | + if ($requeter === false) { |
|
| 385 | + return $query; |
|
| 386 | + } |
|
| 387 | + $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 388 | 388 | |
| 389 | - return $r ? $r : $query; |
|
| 389 | + return $r ? $r : $query; |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | * @return string Texte du orderby préparé |
| 404 | 404 | */ |
| 405 | 405 | function spip_mysql_order($orderby) { |
| 406 | - return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 406 | + return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | |
@@ -426,26 +426,26 @@ discard block |
||
| 426 | 426 | * Contrainte pour clause WHERE |
| 427 | 427 | */ |
| 428 | 428 | function calculer_mysql_where($v) { |
| 429 | - if (!is_array($v)) { |
|
| 430 | - return $v; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - $op = array_shift($v); |
|
| 434 | - if (!($n = count($v))) { |
|
| 435 | - return $op; |
|
| 436 | - } else { |
|
| 437 | - $arg = calculer_mysql_where(array_shift($v)); |
|
| 438 | - if ($n == 1) { |
|
| 439 | - return "$op($arg)"; |
|
| 440 | - } else { |
|
| 441 | - $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 442 | - if ($n == 2) { |
|
| 443 | - return "($arg $op $arg2)"; |
|
| 444 | - } else { |
|
| 445 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - } |
|
| 429 | + if (!is_array($v)) { |
|
| 430 | + return $v; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + $op = array_shift($v); |
|
| 434 | + if (!($n = count($v))) { |
|
| 435 | + return $op; |
|
| 436 | + } else { |
|
| 437 | + $arg = calculer_mysql_where(array_shift($v)); |
|
| 438 | + if ($n == 1) { |
|
| 439 | + return "$op($arg)"; |
|
| 440 | + } else { |
|
| 441 | + $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 442 | + if ($n == 2) { |
|
| 443 | + return "($arg $op $arg2)"; |
|
| 444 | + } else { |
|
| 445 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -460,21 +460,21 @@ discard block |
||
| 460 | 460 | * @return string Texte de l'expression, une partie donc, du texte la requête. |
| 461 | 461 | */ |
| 462 | 462 | function calculer_mysql_expression($expression, $v, $join = 'AND') { |
| 463 | - if (empty($v)) { |
|
| 464 | - return ''; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - $exp = "\n$expression "; |
|
| 468 | - |
|
| 469 | - if (!is_array($v)) { |
|
| 470 | - return $exp . $v; |
|
| 471 | - } else { |
|
| 472 | - if (strtoupper($join) === 'AND') { |
|
| 473 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 474 | - } else { |
|
| 475 | - return $exp . join($join, $v); |
|
| 476 | - } |
|
| 477 | - } |
|
| 463 | + if (empty($v)) { |
|
| 464 | + return ''; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + $exp = "\n$expression "; |
|
| 468 | + |
|
| 469 | + if (!is_array($v)) { |
|
| 470 | + return $exp . $v; |
|
| 471 | + } else { |
|
| 472 | + if (strtoupper($join) === 'AND') { |
|
| 473 | + return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 474 | + } else { |
|
| 475 | + return $exp . join($join, $v); |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | |
@@ -485,26 +485,26 @@ discard block |
||
| 485 | 485 | * @return string Sélection de colonnes pour une clause SELECT |
| 486 | 486 | */ |
| 487 | 487 | function spip_mysql_select_as($args) { |
| 488 | - $res = ''; |
|
| 489 | - foreach ($args as $k => $v) { |
|
| 490 | - if (substr($k, -1) == '@') { |
|
| 491 | - // c'est une jointure qui se refere au from precedent |
|
| 492 | - // pas de virgule |
|
| 493 | - $res .= ' ' . $v; |
|
| 494 | - } else { |
|
| 495 | - if (!is_numeric($k)) { |
|
| 496 | - $p = strpos($v, " "); |
|
| 497 | - if ($p) { |
|
| 498 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 499 | - } else { |
|
| 500 | - $v .= " AS `$k`"; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - $res .= ', ' . $v; |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - return substr($res, 2); |
|
| 488 | + $res = ''; |
|
| 489 | + foreach ($args as $k => $v) { |
|
| 490 | + if (substr($k, -1) == '@') { |
|
| 491 | + // c'est une jointure qui se refere au from precedent |
|
| 492 | + // pas de virgule |
|
| 493 | + $res .= ' ' . $v; |
|
| 494 | + } else { |
|
| 495 | + if (!is_numeric($k)) { |
|
| 496 | + $p = strpos($v, " "); |
|
| 497 | + if ($p) { |
|
| 498 | + $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 499 | + } else { |
|
| 500 | + $v .= " AS `$k`"; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + $res .= ', ' . $v; |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + return substr($res, 2); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | |
@@ -528,42 +528,42 @@ discard block |
||
| 528 | 528 | */ |
| 529 | 529 | function _mysql_traite_query($query, $db = '', $prefixe = '') { |
| 530 | 530 | |
| 531 | - if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 532 | - $pref = '`' . $db . '`.'; |
|
| 533 | - } else { |
|
| 534 | - $pref = ''; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - if ($prefixe) { |
|
| 538 | - $pref .= $prefixe . "_"; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 542 | - $suite = ''; |
|
| 543 | - } else { |
|
| 544 | - $suite = strstr($query, $regs[0]); |
|
| 545 | - $query = substr($query, 0, -strlen($suite)); |
|
| 546 | - // propager le prefixe en cas de requete imbriquee |
|
| 547 | - // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 548 | - // modifier une requete qui est en fait juste du texte dans un champ |
|
| 549 | - if (stripos($suite, "SELECT") !== false) { |
|
| 550 | - list($suite, $textes) = query_echappe_textes($suite); |
|
| 551 | - if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
|
| 552 | - $suite = $r[1] . _mysql_traite_query($r[2], $db, $prefixe); |
|
| 553 | - } |
|
| 554 | - $suite = query_reinjecte_textes($suite, $textes); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 558 | - |
|
| 559 | - // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 560 | - if (defined('_MYSQL_NOPLANES') and _MYSQL_NOPLANES and lire_meta('charset_sql_connexion') == 'utf8') { |
|
| 561 | - include_spip('inc/charsets'); |
|
| 562 | - $r = utf8_noplanes($r); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 566 | - return $r; |
|
| 531 | + if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 532 | + $pref = '`' . $db . '`.'; |
|
| 533 | + } else { |
|
| 534 | + $pref = ''; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + if ($prefixe) { |
|
| 538 | + $pref .= $prefixe . "_"; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 542 | + $suite = ''; |
|
| 543 | + } else { |
|
| 544 | + $suite = strstr($query, $regs[0]); |
|
| 545 | + $query = substr($query, 0, -strlen($suite)); |
|
| 546 | + // propager le prefixe en cas de requete imbriquee |
|
| 547 | + // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 548 | + // modifier une requete qui est en fait juste du texte dans un champ |
|
| 549 | + if (stripos($suite, "SELECT") !== false) { |
|
| 550 | + list($suite, $textes) = query_echappe_textes($suite); |
|
| 551 | + if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
|
| 552 | + $suite = $r[1] . _mysql_traite_query($r[2], $db, $prefixe); |
|
| 553 | + } |
|
| 554 | + $suite = query_reinjecte_textes($suite, $textes); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 558 | + |
|
| 559 | + // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 560 | + if (defined('_MYSQL_NOPLANES') and _MYSQL_NOPLANES and lire_meta('charset_sql_connexion') == 'utf8') { |
|
| 561 | + include_spip('inc/charsets'); |
|
| 562 | + $r = utf8_noplanes($r); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 566 | + return $r; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /** |
@@ -581,13 +581,13 @@ discard block |
||
| 581 | 581 | * - False en cas d'erreur. |
| 582 | 582 | **/ |
| 583 | 583 | function spip_mysql_selectdb($db, $serveur = '', $requeter = true) { |
| 584 | - $link = _mysql_link($serveur); |
|
| 585 | - $ok = mysqli_select_db($link, $db); |
|
| 586 | - if (!$ok) { |
|
| 587 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 588 | - } |
|
| 584 | + $link = _mysql_link($serveur); |
|
| 585 | + $ok = mysqli_select_db($link, $db); |
|
| 586 | + if (!$ok) { |
|
| 587 | + spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 588 | + } |
|
| 589 | 589 | |
| 590 | - return $ok; |
|
| 590 | + return $ok; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | |
@@ -608,14 +608,14 @@ discard block |
||
| 608 | 608 | * Liste de noms de bases de données |
| 609 | 609 | **/ |
| 610 | 610 | function spip_mysql_listdbs($serveur = '', $requeter = true) { |
| 611 | - $dbs = array(); |
|
| 612 | - if ($res = spip_mysql_query("SHOW DATABASES", $serveur)) { |
|
| 613 | - while ($row = mysqli_fetch_assoc($res)) { |
|
| 614 | - $dbs[] = $row['Database']; |
|
| 615 | - } |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - return $dbs; |
|
| 611 | + $dbs = array(); |
|
| 612 | + if ($res = spip_mysql_query("SHOW DATABASES", $serveur)) { |
|
| 613 | + while ($row = mysqli_fetch_assoc($res)) { |
|
| 614 | + $dbs[] = $row['Database']; |
|
| 615 | + } |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + return $dbs; |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | |
@@ -638,72 +638,72 @@ discard block |
||
| 638 | 638 | * - true si la requête réussie, false sinon. |
| 639 | 639 | */ |
| 640 | 640 | function spip_mysql_create( |
| 641 | - $nom, |
|
| 642 | - $champs, |
|
| 643 | - $cles, |
|
| 644 | - $autoinc = false, |
|
| 645 | - $temporary = false, |
|
| 646 | - $serveur = '', |
|
| 647 | - $requeter = true |
|
| 641 | + $nom, |
|
| 642 | + $champs, |
|
| 643 | + $cles, |
|
| 644 | + $autoinc = false, |
|
| 645 | + $temporary = false, |
|
| 646 | + $serveur = '', |
|
| 647 | + $requeter = true |
|
| 648 | 648 | ) { |
| 649 | 649 | |
| 650 | - $query = ''; |
|
| 651 | - $keys = ''; |
|
| 652 | - $s = ''; |
|
| 653 | - $p = ''; |
|
| 654 | - |
|
| 655 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 656 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 657 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 658 | - return; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - $res = spip_mysql_query("SELECT version() as v", $serveur); |
|
| 662 | - if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 663 | - spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - foreach ($cles as $k => $v) { |
|
| 667 | - $keys .= "$s\n\t\t$k ($v)"; |
|
| 668 | - if ($k == "PRIMARY KEY") { |
|
| 669 | - $p = $v; |
|
| 670 | - } |
|
| 671 | - $s = ","; |
|
| 672 | - } |
|
| 673 | - $s = ''; |
|
| 674 | - |
|
| 675 | - $character_set = ""; |
|
| 676 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 677 | - $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 678 | - } |
|
| 679 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 680 | - $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - foreach ($champs as $k => $v) { |
|
| 684 | - $v = _mysql_remplacements_definitions_table($v); |
|
| 685 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 686 | - if (preg_match(',(char|text),i', $defs[1]) |
|
| 687 | - and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 688 | - ) { |
|
| 689 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - $query .= "$s\n\t\t$k $v" |
|
| 694 | - . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 695 | - ? " auto_increment" |
|
| 696 | - : '' |
|
| 697 | - ); |
|
| 698 | - $s = ","; |
|
| 699 | - } |
|
| 700 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 701 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")" |
|
| 702 | - . " ENGINE=MyISAM" |
|
| 703 | - . ($character_set ? " DEFAULT $character_set" : "") |
|
| 704 | - . "\n"; |
|
| 705 | - |
|
| 706 | - return spip_mysql_query($q, $serveur); |
|
| 650 | + $query = ''; |
|
| 651 | + $keys = ''; |
|
| 652 | + $s = ''; |
|
| 653 | + $p = ''; |
|
| 654 | + |
|
| 655 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 656 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 657 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 658 | + return; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + $res = spip_mysql_query("SELECT version() as v", $serveur); |
|
| 662 | + if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 663 | + spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + foreach ($cles as $k => $v) { |
|
| 667 | + $keys .= "$s\n\t\t$k ($v)"; |
|
| 668 | + if ($k == "PRIMARY KEY") { |
|
| 669 | + $p = $v; |
|
| 670 | + } |
|
| 671 | + $s = ","; |
|
| 672 | + } |
|
| 673 | + $s = ''; |
|
| 674 | + |
|
| 675 | + $character_set = ""; |
|
| 676 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 677 | + $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 678 | + } |
|
| 679 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 680 | + $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 681 | + } |
|
| 682 | + |
|
| 683 | + foreach ($champs as $k => $v) { |
|
| 684 | + $v = _mysql_remplacements_definitions_table($v); |
|
| 685 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 686 | + if (preg_match(',(char|text),i', $defs[1]) |
|
| 687 | + and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 688 | + ) { |
|
| 689 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + $query .= "$s\n\t\t$k $v" |
|
| 694 | + . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 695 | + ? " auto_increment" |
|
| 696 | + : '' |
|
| 697 | + ); |
|
| 698 | + $s = ","; |
|
| 699 | + } |
|
| 700 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 701 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")" |
|
| 702 | + . " ENGINE=MyISAM" |
|
| 703 | + . ($character_set ? " DEFAULT $character_set" : "") |
|
| 704 | + . "\n"; |
|
| 705 | + |
|
| 706 | + return spip_mysql_query($q, $serveur); |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | |
@@ -716,17 +716,17 @@ discard block |
||
| 716 | 716 | * Définition SQL adaptée pour MySQL d'un champ de table |
| 717 | 717 | */ |
| 718 | 718 | function _mysql_remplacements_definitions_table($query) { |
| 719 | - // quelques remplacements |
|
| 720 | - $num = "(\s*\([0-9]*\))?"; |
|
| 721 | - $enum = "(\s*\([^\)]*\))?"; |
|
| 719 | + // quelques remplacements |
|
| 720 | + $num = "(\s*\([0-9]*\))?"; |
|
| 721 | + $enum = "(\s*\([^\)]*\))?"; |
|
| 722 | 722 | |
| 723 | - $remplace = array( |
|
| 724 | - '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 725 | - ); |
|
| 723 | + $remplace = array( |
|
| 724 | + '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 725 | + ); |
|
| 726 | 726 | |
| 727 | - $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 727 | + $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 728 | 728 | |
| 729 | - return $query; |
|
| 729 | + return $query; |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | |
@@ -739,7 +739,7 @@ discard block |
||
| 739 | 739 | * @return bool true si la base est créee. |
| 740 | 740 | **/ |
| 741 | 741 | function spip_mysql_create_base($nom, $serveur = '', $requeter = true) { |
| 742 | - return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 742 | + return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | |
@@ -760,19 +760,19 @@ discard block |
||
| 760 | 760 | * - string texte de la requête si $requeter vaut false |
| 761 | 761 | */ |
| 762 | 762 | function spip_mysql_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 763 | - if (!$query_select) { |
|
| 764 | - return false; |
|
| 765 | - } |
|
| 766 | - // vue deja presente |
|
| 767 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 768 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 763 | + if (!$query_select) { |
|
| 764 | + return false; |
|
| 765 | + } |
|
| 766 | + // vue deja presente |
|
| 767 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 768 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 769 | 769 | |
| 770 | - return false; |
|
| 771 | - } |
|
| 770 | + return false; |
|
| 771 | + } |
|
| 772 | 772 | |
| 773 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 773 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 774 | 774 | |
| 775 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 775 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | * - true si la requête a réussie, false sinon |
| 789 | 789 | */ |
| 790 | 790 | function spip_mysql_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 791 | - if ($exist) { |
|
| 792 | - $exist = " IF EXISTS"; |
|
| 793 | - } |
|
| 791 | + if ($exist) { |
|
| 792 | + $exist = " IF EXISTS"; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 795 | + return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -807,11 +807,11 @@ discard block |
||
| 807 | 807 | * - true si la requête a réussie, false sinon |
| 808 | 808 | */ |
| 809 | 809 | function spip_mysql_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 810 | - if ($exist) { |
|
| 811 | - $exist = " IF EXISTS"; |
|
| 812 | - } |
|
| 810 | + if ($exist) { |
|
| 811 | + $exist = " IF EXISTS"; |
|
| 812 | + } |
|
| 813 | 813 | |
| 814 | - return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 814 | + return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | /** |
@@ -828,7 +828,7 @@ discard block |
||
| 828 | 828 | * Ressource à utiliser avec sql_fetch() |
| 829 | 829 | **/ |
| 830 | 830 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 831 | - return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 831 | + return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -844,7 +844,7 @@ discard block |
||
| 844 | 844 | * - true si la requête a réussie, false sinon |
| 845 | 845 | */ |
| 846 | 846 | function spip_mysql_repair($table, $serveur = '', $requeter = true) { |
| 847 | - return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 847 | + return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | |
@@ -868,86 +868,86 @@ discard block |
||
| 868 | 868 | * - array description de la table sinon |
| 869 | 869 | */ |
| 870 | 870 | function spip_mysql_showtable($nom_table, $serveur = '', $requeter = true) { |
| 871 | - $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 872 | - if (!$s) { |
|
| 873 | - return ''; |
|
| 874 | - } |
|
| 875 | - if (!$requeter) { |
|
| 876 | - return $s; |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - list(, $a) = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 880 | - if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 881 | - $desc = $r[1]; |
|
| 882 | - // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 883 | - // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 884 | - if (preg_match("/^(.*?),([^,]*\sKEY[ (].*)$/s", $desc, $r)) { |
|
| 885 | - $namedkeys = $r[2]; |
|
| 886 | - $desc = $r[1]; |
|
| 887 | - } else { |
|
| 888 | - $namedkeys = ""; |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - $fields = array(); |
|
| 892 | - foreach (preg_split("/,\s*`/", $desc) as $v) { |
|
| 893 | - preg_match("/^\s*`?([^`]*)`\s*(.*)/", $v, $r); |
|
| 894 | - $fields[strtolower($r[1])] = $r[2]; |
|
| 895 | - } |
|
| 896 | - $keys = array(); |
|
| 897 | - |
|
| 898 | - foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 899 | - if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/", $v, $r)) { |
|
| 900 | - $k = str_replace("`", '', trim($r[1])); |
|
| 901 | - $t = strtolower(str_replace("`", '', $r[2])); |
|
| 902 | - if ($k && !isset($keys[$k])) { |
|
| 903 | - $keys[$k] = $t; |
|
| 904 | - } else { |
|
| 905 | - $keys[] = $t; |
|
| 906 | - } |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - spip_mysql_free($s); |
|
| 910 | - |
|
| 911 | - return array('field' => $fields, 'key' => $keys); |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 915 | - if ($res) { |
|
| 916 | - $nfields = array(); |
|
| 917 | - $nkeys = array(); |
|
| 918 | - while ($val = spip_mysql_fetch($res)) { |
|
| 919 | - $nfields[$val["Field"]] = $val['Type']; |
|
| 920 | - if ($val['Null'] == 'NO') { |
|
| 921 | - $nfields[$val["Field"]] .= ' NOT NULL'; |
|
| 922 | - } |
|
| 923 | - if ($val['Default'] === '0' || $val['Default']) { |
|
| 924 | - if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 925 | - $nfields[$val["Field"]] .= ' DEFAULT ' . $val['Default']; |
|
| 926 | - } else { |
|
| 927 | - $nfields[$val["Field"]] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 928 | - } |
|
| 929 | - } |
|
| 930 | - if ($val['Extra']) { |
|
| 931 | - $nfields[$val["Field"]] .= ' ' . $val['Extra']; |
|
| 932 | - } |
|
| 933 | - if ($val['Key'] == 'PRI') { |
|
| 934 | - $nkeys['PRIMARY KEY'] = $val["Field"]; |
|
| 935 | - } else { |
|
| 936 | - if ($val['Key'] == 'MUL') { |
|
| 937 | - $nkeys['KEY ' . $val["Field"]] = $val["Field"]; |
|
| 938 | - } else { |
|
| 939 | - if ($val['Key'] == 'UNI') { |
|
| 940 | - $nkeys['UNIQUE KEY ' . $val["Field"]] = $val["Field"]; |
|
| 941 | - } |
|
| 942 | - } |
|
| 943 | - } |
|
| 944 | - } |
|
| 945 | - spip_mysql_free($res); |
|
| 946 | - |
|
| 947 | - return array('field' => $nfields, 'key' => $nkeys); |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - return ""; |
|
| 871 | + $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 872 | + if (!$s) { |
|
| 873 | + return ''; |
|
| 874 | + } |
|
| 875 | + if (!$requeter) { |
|
| 876 | + return $s; |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + list(, $a) = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 880 | + if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 881 | + $desc = $r[1]; |
|
| 882 | + // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 883 | + // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 884 | + if (preg_match("/^(.*?),([^,]*\sKEY[ (].*)$/s", $desc, $r)) { |
|
| 885 | + $namedkeys = $r[2]; |
|
| 886 | + $desc = $r[1]; |
|
| 887 | + } else { |
|
| 888 | + $namedkeys = ""; |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + $fields = array(); |
|
| 892 | + foreach (preg_split("/,\s*`/", $desc) as $v) { |
|
| 893 | + preg_match("/^\s*`?([^`]*)`\s*(.*)/", $v, $r); |
|
| 894 | + $fields[strtolower($r[1])] = $r[2]; |
|
| 895 | + } |
|
| 896 | + $keys = array(); |
|
| 897 | + |
|
| 898 | + foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 899 | + if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/", $v, $r)) { |
|
| 900 | + $k = str_replace("`", '', trim($r[1])); |
|
| 901 | + $t = strtolower(str_replace("`", '', $r[2])); |
|
| 902 | + if ($k && !isset($keys[$k])) { |
|
| 903 | + $keys[$k] = $t; |
|
| 904 | + } else { |
|
| 905 | + $keys[] = $t; |
|
| 906 | + } |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + spip_mysql_free($s); |
|
| 910 | + |
|
| 911 | + return array('field' => $fields, 'key' => $keys); |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 915 | + if ($res) { |
|
| 916 | + $nfields = array(); |
|
| 917 | + $nkeys = array(); |
|
| 918 | + while ($val = spip_mysql_fetch($res)) { |
|
| 919 | + $nfields[$val["Field"]] = $val['Type']; |
|
| 920 | + if ($val['Null'] == 'NO') { |
|
| 921 | + $nfields[$val["Field"]] .= ' NOT NULL'; |
|
| 922 | + } |
|
| 923 | + if ($val['Default'] === '0' || $val['Default']) { |
|
| 924 | + if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 925 | + $nfields[$val["Field"]] .= ' DEFAULT ' . $val['Default']; |
|
| 926 | + } else { |
|
| 927 | + $nfields[$val["Field"]] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | + if ($val['Extra']) { |
|
| 931 | + $nfields[$val["Field"]] .= ' ' . $val['Extra']; |
|
| 932 | + } |
|
| 933 | + if ($val['Key'] == 'PRI') { |
|
| 934 | + $nkeys['PRIMARY KEY'] = $val["Field"]; |
|
| 935 | + } else { |
|
| 936 | + if ($val['Key'] == 'MUL') { |
|
| 937 | + $nkeys['KEY ' . $val["Field"]] = $val["Field"]; |
|
| 938 | + } else { |
|
| 939 | + if ($val['Key'] == 'UNI') { |
|
| 940 | + $nkeys['UNIQUE KEY ' . $val["Field"]] = $val["Field"]; |
|
| 941 | + } |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + } |
|
| 945 | + spip_mysql_free($res); |
|
| 946 | + |
|
| 947 | + return array('field' => $nfields, 'key' => $nkeys); |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + return ""; |
|
| 951 | 951 | } |
| 952 | 952 | |
| 953 | 953 | |
@@ -963,12 +963,12 @@ discard block |
||
| 963 | 963 | * @return array Ligne de résultat |
| 964 | 964 | */ |
| 965 | 965 | function spip_mysql_fetch($r, $t = '', $serveur = '', $requeter = true) { |
| 966 | - if (!$t) { |
|
| 967 | - $t = MYSQLI_ASSOC; |
|
| 968 | - } |
|
| 969 | - if ($r) { |
|
| 970 | - return mysqli_fetch_array($r, $t); |
|
| 971 | - } |
|
| 966 | + if (!$t) { |
|
| 967 | + $t = MYSQLI_ASSOC; |
|
| 968 | + } |
|
| 969 | + if ($r) { |
|
| 970 | + return mysqli_fetch_array($r, $t); |
|
| 971 | + } |
|
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | /** |
@@ -981,9 +981,9 @@ discard block |
||
| 981 | 981 | * @return bool True si déplacement réussi, false sinon. |
| 982 | 982 | **/ |
| 983 | 983 | function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 984 | - if ($r and mysqli_num_rows($r)) { |
|
| 985 | - return mysqli_data_seek($r, $row_number); |
|
| 986 | - } |
|
| 984 | + if ($r and mysqli_num_rows($r)) { |
|
| 985 | + return mysqli_data_seek($r, $row_number); |
|
| 986 | + } |
|
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | |
@@ -1001,26 +1001,26 @@ discard block |
||
| 1001 | 1001 | * - int Nombre de lignes (0 si la requête n'a pas réussie) |
| 1002 | 1002 | **/ |
| 1003 | 1003 | function spip_mysql_countsel( |
| 1004 | - $from = array(), |
|
| 1005 | - $where = array(), |
|
| 1006 | - $groupby = '', |
|
| 1007 | - $having = array(), |
|
| 1008 | - $serveur = '', |
|
| 1009 | - $requeter = true |
|
| 1004 | + $from = array(), |
|
| 1005 | + $where = array(), |
|
| 1006 | + $groupby = '', |
|
| 1007 | + $having = array(), |
|
| 1008 | + $serveur = '', |
|
| 1009 | + $requeter = true |
|
| 1010 | 1010 | ) { |
| 1011 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1012 | - |
|
| 1013 | - $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1014 | - if (!$requeter) { |
|
| 1015 | - return $r; |
|
| 1016 | - } |
|
| 1017 | - if (!$r instanceof mysqli_result) { |
|
| 1018 | - return 0; |
|
| 1019 | - } |
|
| 1020 | - list($c) = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1021 | - mysqli_free_result($r); |
|
| 1022 | - |
|
| 1023 | - return $c; |
|
| 1011 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1012 | + |
|
| 1013 | + $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1014 | + if (!$requeter) { |
|
| 1015 | + return $r; |
|
| 1016 | + } |
|
| 1017 | + if (!$r instanceof mysqli_result) { |
|
| 1018 | + return 0; |
|
| 1019 | + } |
|
| 1020 | + list($c) = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1021 | + mysqli_free_result($r); |
|
| 1022 | + |
|
| 1023 | + return $c; |
|
| 1024 | 1024 | } |
| 1025 | 1025 | |
| 1026 | 1026 | |
@@ -1043,16 +1043,16 @@ discard block |
||
| 1043 | 1043 | * Erreur eventuelle |
| 1044 | 1044 | **/ |
| 1045 | 1045 | function spip_mysql_error($query = '', $serveur = '', $requeter = true) { |
| 1046 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1047 | - $s = mysqli_error($link); |
|
| 1048 | - if ($s) { |
|
| 1049 | - $trace = debug_backtrace(); |
|
| 1050 | - if ($trace[0]['function'] != "spip_mysql_error") { |
|
| 1051 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1052 | - } |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - return $s; |
|
| 1046 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1047 | + $s = mysqli_error($link); |
|
| 1048 | + if ($s) { |
|
| 1049 | + $trace = debug_backtrace(); |
|
| 1050 | + if ($trace[0]['function'] != "spip_mysql_error") { |
|
| 1051 | + spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1052 | + } |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + return $s; |
|
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | |
@@ -1067,18 +1067,18 @@ discard block |
||
| 1067 | 1067 | * 0, pas d'erreur. Autre, numéro de l'erreur. |
| 1068 | 1068 | **/ |
| 1069 | 1069 | function spip_mysql_errno($serveur = '', $requeter = true) { |
| 1070 | - $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 1071 | - $s = mysqli_errno($link); |
|
| 1072 | - // 2006 MySQL server has gone away |
|
| 1073 | - // 2013 Lost connection to MySQL server during query |
|
| 1074 | - if (in_array($s, array(2006, 2013))) { |
|
| 1075 | - define('spip_interdire_cache', true); |
|
| 1076 | - } |
|
| 1077 | - if ($s) { |
|
| 1078 | - spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - return $s; |
|
| 1070 | + $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 1071 | + $s = mysqli_errno($link); |
|
| 1072 | + // 2006 MySQL server has gone away |
|
| 1073 | + // 2013 Lost connection to MySQL server during query |
|
| 1074 | + if (in_array($s, array(2006, 2013))) { |
|
| 1075 | + define('spip_interdire_cache', true); |
|
| 1076 | + } |
|
| 1077 | + if ($s) { |
|
| 1078 | + spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + return $s; |
|
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | |
@@ -1092,9 +1092,9 @@ discard block |
||
| 1092 | 1092 | * @return int Nombre de lignes |
| 1093 | 1093 | */ |
| 1094 | 1094 | function spip_mysql_count($r, $serveur = '', $requeter = true) { |
| 1095 | - if ($r) { |
|
| 1096 | - return mysqli_num_rows($r); |
|
| 1097 | - } |
|
| 1095 | + if ($r) { |
|
| 1096 | + return mysqli_num_rows($r); |
|
| 1097 | + } |
|
| 1098 | 1098 | } |
| 1099 | 1099 | |
| 1100 | 1100 | |
@@ -1110,7 +1110,7 @@ discard block |
||
| 1110 | 1110 | * @return bool True si réussi |
| 1111 | 1111 | */ |
| 1112 | 1112 | function spip_mysql_free($r, $serveur = '', $requeter = true) { |
| 1113 | - return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1113 | + return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | |
@@ -1138,38 +1138,38 @@ discard block |
||
| 1138 | 1138 | **/ |
| 1139 | 1139 | function spip_mysql_insert($table, $champs, $valeurs, $desc = array(), $serveur = '', $requeter = true) { |
| 1140 | 1140 | |
| 1141 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1142 | - $link = $connexion['link']; |
|
| 1143 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1144 | - |
|
| 1145 | - $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1146 | - if (!$requeter) { |
|
| 1147 | - return $query; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - if (isset($_GET['var_profile'])) { |
|
| 1151 | - include_spip('public/tracer'); |
|
| 1152 | - $t = trace_query_start(); |
|
| 1153 | - $e = ''; |
|
| 1154 | - } else { |
|
| 1155 | - $t = 0; |
|
| 1156 | - } |
|
| 1157 | - |
|
| 1158 | - $connexion['last'] = $query; |
|
| 1159 | - #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1160 | - $r = false; |
|
| 1161 | - if (mysqli_query($link, $query)) { |
|
| 1162 | - $r = mysqli_insert_id($link); |
|
| 1163 | - } else { |
|
| 1164 | - // Log de l'erreur eventuelle |
|
| 1165 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 1166 | - $e .= spip_mysql_error($query, $serveur); |
|
| 1167 | - } // et du fautif |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1171 | - |
|
| 1172 | - // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1141 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1142 | + $link = $connexion['link']; |
|
| 1143 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1144 | + |
|
| 1145 | + $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1146 | + if (!$requeter) { |
|
| 1147 | + return $query; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + if (isset($_GET['var_profile'])) { |
|
| 1151 | + include_spip('public/tracer'); |
|
| 1152 | + $t = trace_query_start(); |
|
| 1153 | + $e = ''; |
|
| 1154 | + } else { |
|
| 1155 | + $t = 0; |
|
| 1156 | + } |
|
| 1157 | + |
|
| 1158 | + $connexion['last'] = $query; |
|
| 1159 | + #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1160 | + $r = false; |
|
| 1161 | + if (mysqli_query($link, $query)) { |
|
| 1162 | + $r = mysqli_insert_id($link); |
|
| 1163 | + } else { |
|
| 1164 | + // Log de l'erreur eventuelle |
|
| 1165 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 1166 | + $e .= spip_mysql_error($query, $serveur); |
|
| 1167 | + } // et du fautif |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1171 | + |
|
| 1172 | + // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | 1175 | /** |
@@ -1194,20 +1194,20 @@ discard block |
||
| 1194 | 1194 | **/ |
| 1195 | 1195 | function spip_mysql_insertq($table, $couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
| 1196 | 1196 | |
| 1197 | - if (!$desc) { |
|
| 1198 | - $desc = description_table($table, $serveur); |
|
| 1199 | - } |
|
| 1200 | - if (!$desc) { |
|
| 1201 | - $couples = array(); |
|
| 1202 | - } |
|
| 1203 | - $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1197 | + if (!$desc) { |
|
| 1198 | + $desc = description_table($table, $serveur); |
|
| 1199 | + } |
|
| 1200 | + if (!$desc) { |
|
| 1201 | + $couples = array(); |
|
| 1202 | + } |
|
| 1203 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1204 | 1204 | |
| 1205 | - foreach ($couples as $champ => $val) { |
|
| 1206 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1207 | - } |
|
| 1205 | + foreach ($couples as $champ => $val) { |
|
| 1206 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1207 | + } |
|
| 1208 | 1208 | |
| 1209 | - return spip_mysql_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 1210 | - $serveur, $requeter); |
|
| 1209 | + return spip_mysql_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 1210 | + $serveur, $requeter); |
|
| 1211 | 1211 | } |
| 1212 | 1212 | |
| 1213 | 1213 | |
@@ -1232,34 +1232,34 @@ discard block |
||
| 1232 | 1232 | **/ |
| 1233 | 1233 | function spip_mysql_insertq_multi($table, $tab_couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
| 1234 | 1234 | |
| 1235 | - if (!$desc) { |
|
| 1236 | - $desc = description_table($table, $serveur); |
|
| 1237 | - } |
|
| 1238 | - if (!$desc) { |
|
| 1239 | - $tab_couples = array(); |
|
| 1240 | - } |
|
| 1241 | - $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1242 | - |
|
| 1243 | - $cles = "(" . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1244 | - $valeurs = array(); |
|
| 1245 | - $r = false; |
|
| 1246 | - |
|
| 1247 | - // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1248 | - foreach ($tab_couples as $couples) { |
|
| 1249 | - foreach ($couples as $champ => $val) { |
|
| 1250 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1251 | - } |
|
| 1252 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1253 | - if (count($valeurs) >= 100) { |
|
| 1254 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1255 | - $valeurs = array(); |
|
| 1256 | - } |
|
| 1257 | - } |
|
| 1258 | - if (count($valeurs)) { |
|
| 1259 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1260 | - } |
|
| 1261 | - |
|
| 1262 | - return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1235 | + if (!$desc) { |
|
| 1236 | + $desc = description_table($table, $serveur); |
|
| 1237 | + } |
|
| 1238 | + if (!$desc) { |
|
| 1239 | + $tab_couples = array(); |
|
| 1240 | + } |
|
| 1241 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1242 | + |
|
| 1243 | + $cles = "(" . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1244 | + $valeurs = array(); |
|
| 1245 | + $r = false; |
|
| 1246 | + |
|
| 1247 | + // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1248 | + foreach ($tab_couples as $couples) { |
|
| 1249 | + foreach ($couples as $champ => $val) { |
|
| 1250 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1251 | + } |
|
| 1252 | + $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1253 | + if (count($valeurs) >= 100) { |
|
| 1254 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1255 | + $valeurs = array(); |
|
| 1256 | + } |
|
| 1257 | + } |
|
| 1258 | + if (count($valeurs)) { |
|
| 1259 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1260 | + } |
|
| 1261 | + |
|
| 1262 | + return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | 1265 | /** |
@@ -1284,17 +1284,17 @@ discard block |
||
| 1284 | 1284 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 1285 | 1285 | */ |
| 1286 | 1286 | function spip_mysql_update($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1287 | - $set = array(); |
|
| 1288 | - foreach ($champs as $champ => $val) { |
|
| 1289 | - $set[] = $champ . "=$val"; |
|
| 1290 | - } |
|
| 1291 | - if (!empty($set)) { |
|
| 1292 | - return spip_mysql_query( |
|
| 1293 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1294 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1295 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1296 | - $serveur, $requeter); |
|
| 1297 | - } |
|
| 1287 | + $set = array(); |
|
| 1288 | + foreach ($champs as $champ => $val) { |
|
| 1289 | + $set[] = $champ . "=$val"; |
|
| 1290 | + } |
|
| 1291 | + if (!empty($set)) { |
|
| 1292 | + return spip_mysql_query( |
|
| 1293 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1294 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1295 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1296 | + $serveur, $requeter); |
|
| 1297 | + } |
|
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | 1300 | /** |
@@ -1327,27 +1327,27 @@ discard block |
||
| 1327 | 1327 | */ |
| 1328 | 1328 | function spip_mysql_updateq($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1329 | 1329 | |
| 1330 | - if (!$champs) { |
|
| 1331 | - return; |
|
| 1332 | - } |
|
| 1333 | - if (!$desc) { |
|
| 1334 | - $desc = description_table($table, $serveur); |
|
| 1335 | - } |
|
| 1336 | - if (!$desc) { |
|
| 1337 | - $champs = array(); |
|
| 1338 | - } else { |
|
| 1339 | - $fields = $desc['field']; |
|
| 1340 | - } |
|
| 1341 | - $set = array(); |
|
| 1342 | - foreach ($champs as $champ => $val) { |
|
| 1343 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - return spip_mysql_query( |
|
| 1347 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1348 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1349 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1350 | - $serveur, $requeter); |
|
| 1330 | + if (!$champs) { |
|
| 1331 | + return; |
|
| 1332 | + } |
|
| 1333 | + if (!$desc) { |
|
| 1334 | + $desc = description_table($table, $serveur); |
|
| 1335 | + } |
|
| 1336 | + if (!$desc) { |
|
| 1337 | + $champs = array(); |
|
| 1338 | + } else { |
|
| 1339 | + $fields = $desc['field']; |
|
| 1340 | + } |
|
| 1341 | + $set = array(); |
|
| 1342 | + foreach ($champs as $champ => $val) { |
|
| 1343 | + $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + return spip_mysql_query( |
|
| 1347 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1348 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1349 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1350 | + $serveur, $requeter); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | |
| 1353 | 1353 | /** |
@@ -1363,20 +1363,20 @@ discard block |
||
| 1363 | 1363 | * - False en cas d'erreur. |
| 1364 | 1364 | **/ |
| 1365 | 1365 | function spip_mysql_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 1366 | - $res = spip_mysql_query( |
|
| 1367 | - calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1368 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1369 | - $serveur, $requeter); |
|
| 1370 | - if (!$requeter) { |
|
| 1371 | - return $res; |
|
| 1372 | - } |
|
| 1373 | - if ($res) { |
|
| 1374 | - $link = _mysql_link($serveur); |
|
| 1375 | - |
|
| 1376 | - return mysqli_affected_rows($link); |
|
| 1377 | - } else { |
|
| 1378 | - return false; |
|
| 1379 | - } |
|
| 1366 | + $res = spip_mysql_query( |
|
| 1367 | + calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1368 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1369 | + $serveur, $requeter); |
|
| 1370 | + if (!$requeter) { |
|
| 1371 | + return $res; |
|
| 1372 | + } |
|
| 1373 | + if ($res) { |
|
| 1374 | + $link = _mysql_link($serveur); |
|
| 1375 | + |
|
| 1376 | + return mysqli_affected_rows($link); |
|
| 1377 | + } else { |
|
| 1378 | + return false; |
|
| 1379 | + } |
|
| 1380 | 1380 | } |
| 1381 | 1381 | |
| 1382 | 1382 | |
@@ -1405,8 +1405,8 @@ discard block |
||
| 1405 | 1405 | * - False en cas d'erreur. |
| 1406 | 1406 | **/ |
| 1407 | 1407 | function spip_mysql_replace($table, $couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1408 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',', |
|
| 1409 | - array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1408 | + return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',', |
|
| 1409 | + array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | |
@@ -1435,14 +1435,14 @@ discard block |
||
| 1435 | 1435 | * - False en cas d'erreur. |
| 1436 | 1436 | **/ |
| 1437 | 1437 | function spip_mysql_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1438 | - $cles = "(" . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1439 | - $valeurs = array(); |
|
| 1440 | - foreach ($tab_couples as $couples) { |
|
| 1441 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1442 | - } |
|
| 1443 | - $valeurs = implode(', ', $valeurs); |
|
| 1444 | - |
|
| 1445 | - return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1438 | + $cles = "(" . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1439 | + $valeurs = array(); |
|
| 1440 | + foreach ($tab_couples as $couples) { |
|
| 1441 | + $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1442 | + } |
|
| 1443 | + $valeurs = implode(', ', $valeurs); |
|
| 1444 | + |
|
| 1445 | + return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | 1448 | |
@@ -1457,32 +1457,32 @@ discard block |
||
| 1457 | 1457 | * @return string Texte de sélection pour la requête |
| 1458 | 1458 | */ |
| 1459 | 1459 | function spip_mysql_multi($objet, $lang) { |
| 1460 | - $lengthlang = strlen("[$lang]"); |
|
| 1461 | - $posmulti = "INSTR(" . $objet . ", '<multi>')"; |
|
| 1462 | - $posfinmulti = "INSTR(" . $objet . ", '</multi>')"; |
|
| 1463 | - $debutchaine = "LEFT(" . $objet . ", $posmulti-1)"; |
|
| 1464 | - $finchaine = "RIGHT(" . $objet . ", CHAR_LENGTH(" . $objet . ") -(7+$posfinmulti))"; |
|
| 1465 | - $chainemulti = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1466 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1467 | - $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1468 | - $chainelang = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1469 | - $posfinlang = "INSTR(" . $chainelang . ", '[')"; |
|
| 1470 | - $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1471 | - //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1472 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1473 | - " TRIM(" . $objet . "), " . |
|
| 1474 | - " CONCAT( " . |
|
| 1475 | - " $debutchaine, " . |
|
| 1476 | - " IF( " . |
|
| 1477 | - " $poslang = 0, " . |
|
| 1478 | - " $chainemulti, " . |
|
| 1479 | - " $chainelang" . |
|
| 1480 | - " ), " . |
|
| 1481 | - " $finchaine" . |
|
| 1482 | - " ) " . |
|
| 1483 | - "))) AS multi"; |
|
| 1484 | - |
|
| 1485 | - return $retour; |
|
| 1460 | + $lengthlang = strlen("[$lang]"); |
|
| 1461 | + $posmulti = "INSTR(" . $objet . ", '<multi>')"; |
|
| 1462 | + $posfinmulti = "INSTR(" . $objet . ", '</multi>')"; |
|
| 1463 | + $debutchaine = "LEFT(" . $objet . ", $posmulti-1)"; |
|
| 1464 | + $finchaine = "RIGHT(" . $objet . ", CHAR_LENGTH(" . $objet . ") -(7+$posfinmulti))"; |
|
| 1465 | + $chainemulti = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1466 | + $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1467 | + $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1468 | + $chainelang = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1469 | + $posfinlang = "INSTR(" . $chainelang . ", '[')"; |
|
| 1470 | + $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1471 | + //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1472 | + $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1473 | + " TRIM(" . $objet . "), " . |
|
| 1474 | + " CONCAT( " . |
|
| 1475 | + " $debutchaine, " . |
|
| 1476 | + " IF( " . |
|
| 1477 | + " $poslang = 0, " . |
|
| 1478 | + " $chainemulti, " . |
|
| 1479 | + " $chainelang" . |
|
| 1480 | + " ), " . |
|
| 1481 | + " $finchaine" . |
|
| 1482 | + " ) " . |
|
| 1483 | + "))) AS multi"; |
|
| 1484 | + |
|
| 1485 | + return $retour; |
|
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | 1488 | /** |
@@ -1496,7 +1496,7 @@ discard block |
||
| 1496 | 1496 | * Valeur hexadécimale pour MySQL |
| 1497 | 1497 | **/ |
| 1498 | 1498 | function spip_mysql_hex($v) { |
| 1499 | - return "0x" . $v; |
|
| 1499 | + return "0x" . $v; |
|
| 1500 | 1500 | } |
| 1501 | 1501 | |
| 1502 | 1502 | /** |
@@ -1512,22 +1512,22 @@ discard block |
||
| 1512 | 1512 | * Donnée prête à être utilisée par le gestionnaire SQL |
| 1513 | 1513 | */ |
| 1514 | 1514 | function spip_mysql_quote($v, $type = '') { |
| 1515 | - if ($type) { |
|
| 1516 | - if (!is_array($v)) { |
|
| 1517 | - return spip_mysql_cite($v, $type); |
|
| 1518 | - } |
|
| 1519 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1520 | - foreach ($v as $k => $r) { |
|
| 1521 | - $v[$k] = spip_mysql_quote($r, $type); |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - return $v; |
|
| 1525 | - } |
|
| 1526 | - // si on ne connait pas le type, s'en remettre a _q : |
|
| 1527 | - // on ne fera pas mieux |
|
| 1528 | - else { |
|
| 1529 | - return _q($v); |
|
| 1530 | - } |
|
| 1515 | + if ($type) { |
|
| 1516 | + if (!is_array($v)) { |
|
| 1517 | + return spip_mysql_cite($v, $type); |
|
| 1518 | + } |
|
| 1519 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1520 | + foreach ($v as $k => $r) { |
|
| 1521 | + $v[$k] = spip_mysql_quote($r, $type); |
|
| 1522 | + } |
|
| 1523 | + |
|
| 1524 | + return $v; |
|
| 1525 | + } |
|
| 1526 | + // si on ne connait pas le type, s'en remettre a _q : |
|
| 1527 | + // on ne fera pas mieux |
|
| 1528 | + else { |
|
| 1529 | + return _q($v); |
|
| 1530 | + } |
|
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 1533 | 1533 | /** |
@@ -1543,17 +1543,17 @@ discard block |
||
| 1543 | 1543 | * Expression SQL |
| 1544 | 1544 | **/ |
| 1545 | 1545 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1546 | - return '(' |
|
| 1547 | - . $champ |
|
| 1548 | - . (($interval <= 0) ? '>' : '<') |
|
| 1549 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1550 | - . '(' |
|
| 1551 | - . sql_quote(date('Y-m-d H:i:s')) |
|
| 1552 | - . ', INTERVAL ' |
|
| 1553 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1554 | - . ' ' |
|
| 1555 | - . $unite |
|
| 1556 | - . '))'; |
|
| 1546 | + return '(' |
|
| 1547 | + . $champ |
|
| 1548 | + . (($interval <= 0) ? '>' : '<') |
|
| 1549 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1550 | + . '(' |
|
| 1551 | + . sql_quote(date('Y-m-d H:i:s')) |
|
| 1552 | + . ', INTERVAL ' |
|
| 1553 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1554 | + . ' ' |
|
| 1555 | + . $unite |
|
| 1556 | + . '))'; |
|
| 1557 | 1557 | } |
| 1558 | 1558 | |
| 1559 | 1559 | |
@@ -1577,21 +1577,21 @@ discard block |
||
| 1577 | 1577 | * Expression de requête SQL |
| 1578 | 1578 | **/ |
| 1579 | 1579 | function spip_mysql_in($val, $valeurs, $not = '', $serveur = '', $requeter = true) { |
| 1580 | - $n = $i = 0; |
|
| 1581 | - $in_sql = ""; |
|
| 1582 | - while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1583 | - if ((++$i) >= 255) { |
|
| 1584 | - $in_sql .= "($val $not IN (" . |
|
| 1585 | - substr($valeurs, 0, $n) . |
|
| 1586 | - "))\n" . |
|
| 1587 | - ($not ? "AND\t" : "OR\t"); |
|
| 1588 | - $valeurs = substr($valeurs, $n + 1); |
|
| 1589 | - $i = $n = 0; |
|
| 1590 | - } |
|
| 1591 | - } |
|
| 1592 | - $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1593 | - |
|
| 1594 | - return "($in_sql)"; |
|
| 1580 | + $n = $i = 0; |
|
| 1581 | + $in_sql = ""; |
|
| 1582 | + while ($n = strpos($valeurs, ',', $n + 1)) { |
|
| 1583 | + if ((++$i) >= 255) { |
|
| 1584 | + $in_sql .= "($val $not IN (" . |
|
| 1585 | + substr($valeurs, 0, $n) . |
|
| 1586 | + "))\n" . |
|
| 1587 | + ($not ? "AND\t" : "OR\t"); |
|
| 1588 | + $valeurs = substr($valeurs, $n + 1); |
|
| 1589 | + $i = $n = 0; |
|
| 1590 | + } |
|
| 1591 | + } |
|
| 1592 | + $in_sql .= "($val $not IN ($valeurs))"; |
|
| 1593 | + |
|
| 1594 | + return "($in_sql)"; |
|
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | 1597 | |
@@ -1608,16 +1608,16 @@ discard block |
||
| 1608 | 1608 | * @return string Expression de requête SQL |
| 1609 | 1609 | */ |
| 1610 | 1610 | function calcul_mysql_in($val, $valeurs, $not = '') { |
| 1611 | - if (is_array($valeurs)) { |
|
| 1612 | - $valeurs = join(',', array_map('_q', $valeurs)); |
|
| 1613 | - } elseif ($valeurs[0] === ',') { |
|
| 1614 | - $valeurs = substr($valeurs, 1); |
|
| 1615 | - } |
|
| 1616 | - if (!strlen(trim($valeurs))) { |
|
| 1617 | - return ($not ? "0=0" : '0=1'); |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - return spip_mysql_in($val, $valeurs, $not); |
|
| 1611 | + if (is_array($valeurs)) { |
|
| 1612 | + $valeurs = join(',', array_map('_q', $valeurs)); |
|
| 1613 | + } elseif ($valeurs[0] === ',') { |
|
| 1614 | + $valeurs = substr($valeurs, 1); |
|
| 1615 | + } |
|
| 1616 | + if (!strlen(trim($valeurs))) { |
|
| 1617 | + return ($not ? "0=0" : '0=1'); |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + return spip_mysql_in($val, $valeurs, $not); |
|
| 1621 | 1621 | } |
| 1622 | 1622 | |
| 1623 | 1623 | |
@@ -1629,26 +1629,26 @@ discard block |
||
| 1629 | 1629 | * @return string|number Texte ou nombre échappé |
| 1630 | 1630 | */ |
| 1631 | 1631 | function spip_mysql_cite($v, $type) { |
| 1632 | - if (is_null($v) |
|
| 1633 | - and stripos($type, "NOT NULL") === false |
|
| 1634 | - ) { |
|
| 1635 | - return 'NULL'; |
|
| 1636 | - } // null php se traduit en NULL SQL |
|
| 1637 | - if (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1638 | - return $v; |
|
| 1639 | - } |
|
| 1640 | - if (sql_test_int($type)) { |
|
| 1641 | - if (is_numeric($v) or (ctype_xdigit(substr($v, 2)) |
|
| 1642 | - and $v[0] == '0' and $v[1] == 'x') |
|
| 1643 | - ) { |
|
| 1644 | - return $v; |
|
| 1645 | - } // si pas numerique, forcer le intval |
|
| 1646 | - else { |
|
| 1647 | - return intval($v); |
|
| 1648 | - } |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - return ("'" . addslashes($v) . "'"); |
|
| 1632 | + if (is_null($v) |
|
| 1633 | + and stripos($type, "NOT NULL") === false |
|
| 1634 | + ) { |
|
| 1635 | + return 'NULL'; |
|
| 1636 | + } // null php se traduit en NULL SQL |
|
| 1637 | + if (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1638 | + return $v; |
|
| 1639 | + } |
|
| 1640 | + if (sql_test_int($type)) { |
|
| 1641 | + if (is_numeric($v) or (ctype_xdigit(substr($v, 2)) |
|
| 1642 | + and $v[0] == '0' and $v[1] == 'x') |
|
| 1643 | + ) { |
|
| 1644 | + return $v; |
|
| 1645 | + } // si pas numerique, forcer le intval |
|
| 1646 | + else { |
|
| 1647 | + return intval($v); |
|
| 1648 | + } |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + return ("'" . addslashes($v) . "'"); |
|
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | |
@@ -1672,21 +1672,21 @@ discard block |
||
| 1672 | 1672 | */ |
| 1673 | 1673 | function spip_get_lock($nom, $timeout = 0) { |
| 1674 | 1674 | |
| 1675 | - define('_LOCK_TIME', intval(time() / 3600 - 316982)); |
|
| 1675 | + define('_LOCK_TIME', intval(time() / 3600 - 316982)); |
|
| 1676 | 1676 | |
| 1677 | - $connexion = &$GLOBALS['connexions'][0]; |
|
| 1678 | - $bd = $connexion['db']; |
|
| 1679 | - $prefixe = $connexion['prefixe']; |
|
| 1680 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1677 | + $connexion = &$GLOBALS['connexions'][0]; |
|
| 1678 | + $bd = $connexion['db']; |
|
| 1679 | + $prefixe = $connexion['prefixe']; |
|
| 1680 | + $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1681 | 1681 | |
| 1682 | - $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1682 | + $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1683 | 1683 | |
| 1684 | - $q = @sql_fetch(mysqli_query(_mysql_link(), $q)); |
|
| 1685 | - if (!$q) { |
|
| 1686 | - spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1687 | - } |
|
| 1684 | + $q = @sql_fetch(mysqli_query(_mysql_link(), $q)); |
|
| 1685 | + if (!$q) { |
|
| 1686 | + spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1687 | + } |
|
| 1688 | 1688 | |
| 1689 | - return $q['n']; |
|
| 1689 | + return $q['n']; |
|
| 1690 | 1690 | } |
| 1691 | 1691 | |
| 1692 | 1692 | |
@@ -1703,13 +1703,13 @@ discard block |
||
| 1703 | 1703 | */ |
| 1704 | 1704 | function spip_release_lock($nom) { |
| 1705 | 1705 | |
| 1706 | - $connexion = &$GLOBALS['connexions'][0]; |
|
| 1707 | - $bd = $connexion['db']; |
|
| 1708 | - $prefixe = $connexion['prefixe']; |
|
| 1709 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1706 | + $connexion = &$GLOBALS['connexions'][0]; |
|
| 1707 | + $bd = $connexion['db']; |
|
| 1708 | + $prefixe = $connexion['prefixe']; |
|
| 1709 | + $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1710 | 1710 | |
| 1711 | - $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1712 | - mysqli_query(_mysql_link(), $q); |
|
| 1711 | + $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1712 | + mysqli_query(_mysql_link(), $q); |
|
| 1713 | 1713 | } |
| 1714 | 1714 | |
| 1715 | 1715 | |
@@ -1720,7 +1720,7 @@ discard block |
||
| 1720 | 1720 | * True si on a les fonctions, false sinon |
| 1721 | 1721 | */ |
| 1722 | 1722 | function spip_versions_mysql() { |
| 1723 | - return function_exists('mysqli_query'); |
|
| 1723 | + return function_exists('mysqli_query'); |
|
| 1724 | 1724 | } |
| 1725 | 1725 | |
| 1726 | 1726 | |
@@ -1733,20 +1733,20 @@ discard block |
||
| 1733 | 1733 | * - chaîne : code compilé pour le faire désactiver par SPIP sinon |
| 1734 | 1734 | */ |
| 1735 | 1735 | function test_rappel_nom_base_mysql($server_db) { |
| 1736 | - $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1737 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1738 | - $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1736 | + $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1737 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1738 | + $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1739 | 1739 | |
| 1740 | - if ($ok) { |
|
| 1741 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1740 | + if ($ok) { |
|
| 1741 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1742 | 1742 | |
| 1743 | - return ''; |
|
| 1744 | - } else { |
|
| 1745 | - $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1743 | + return ''; |
|
| 1744 | + } else { |
|
| 1745 | + $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1746 | 1746 | |
| 1747 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1748 | - "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1749 | - } |
|
| 1747 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1748 | + "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1749 | + } |
|
| 1750 | 1750 | } |
| 1751 | 1751 | |
| 1752 | 1752 | /** |
@@ -1760,13 +1760,13 @@ discard block |
||
| 1760 | 1760 | * - chaîne : code compilé pour l'indiquer le résultat du test à SPIP |
| 1761 | 1761 | */ |
| 1762 | 1762 | function test_sql_mode_mysql($server_db) { |
| 1763 | - $res = sql_select("version() as v", '', '', '', '', '', '', $server_db); |
|
| 1764 | - $row = sql_fetch($res, $server_db); |
|
| 1765 | - if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1766 | - defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1763 | + $res = sql_select("version() as v", '', '', '', '', '', '', $server_db); |
|
| 1764 | + $row = sql_fetch($res, $server_db); |
|
| 1765 | + if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1766 | + defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1767 | 1767 | |
| 1768 | - return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1769 | - } |
|
| 1768 | + return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1769 | + } |
|
| 1770 | 1770 | |
| 1771 | - return ''; |
|
| 1771 | + return ''; |
|
| 1772 | 1772 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
| 49 | 49 | if ( |
| 50 | 50 | $port and !is_numeric($socket = $port) |
| 51 | - and (!$host or $host=='localhost')) { |
|
| 51 | + and (!$host or $host == 'localhost')) { |
|
| 52 | 52 | $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
| 53 | 53 | } |
| 54 | 54 | elseif ($port) { |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | if (!$link) { |
| 62 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 62 | + spip_log('Echec mysqli_connect. Erreur : '.mysqli_connect_error(), 'mysql.'._LOG_HS); |
|
| 63 | 63 | |
| 64 | 64 | return false; |
| 65 | 65 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle" : 'impossible'), |
|
| 79 | + spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe ".($ok ? "operationnelle" : 'impossible'), |
|
| 80 | 80 | _LOG_DEBUG); |
| 81 | 81 | |
| 82 | 82 | return !$ok ? false : array( |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 167 | 167 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 168 | - spip_log("changement de charset sql : " . "SET NAMES " . _q($charset), _LOG_DEBUG); |
|
| 168 | + spip_log("changement de charset sql : "."SET NAMES "._q($charset), _LOG_DEBUG); |
|
| 169 | 169 | |
| 170 | - return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES " . _q($charset)); |
|
| 170 | + return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES "._q($charset)); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | function spip_mysql_get_charset($charset = array(), $serveur = '', $requeter = true) { |
| 183 | 183 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 184 | 184 | $connexion['last'] = $c = "SHOW CHARACTER SET" |
| 185 | - . (!$charset ? '' : (" LIKE " . _q($charset['charset']))); |
|
| 185 | + . (!$charset ? '' : (" LIKE "._q($charset['charset']))); |
|
| 186 | 186 | |
| 187 | 187 | return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
| 188 | 188 | } |
@@ -242,14 +242,14 @@ discard block |
||
| 242 | 242 | $debug = ''; |
| 243 | 243 | if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
| 244 | 244 | if (isset($GLOBALS['debug']['aucasou'])) { |
| 245 | - list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | - $debug .= "BOUCLE$id @ " . (isset($infos[0]) ? $infos[0] : '') . " | "; |
|
| 245 | + list(, $id,, $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | + $debug .= "BOUCLE$id @ ".(isset($infos[0]) ? $infos[0] : '')." | "; |
|
| 247 | 247 | } |
| 248 | - $debug .= $_SERVER['REQUEST_URI'] . ' + ' . $GLOBALS['ip']; |
|
| 249 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 248 | + $debug .= $_SERVER['REQUEST_URI'].' + '.$GLOBALS['ip']; |
|
| 249 | + $debug = ' /* '.mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)).' */'; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - $r = mysqli_query($link, $query . $debug); |
|
| 252 | + $r = mysqli_query($link, $query.$debug); |
|
| 253 | 253 | |
| 254 | 254 | //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
| 255 | 255 | if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 263 | 263 | $link = $connexion['link']; |
| 264 | 264 | //On retente au cas où |
| 265 | - $r = mysqli_query($link, $query . $debug); |
|
| 265 | + $r = mysqli_query($link, $query.$debug); |
|
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | // d'utiliser ceux-ci, copie-colle de phpmyadmin |
| 291 | 291 | $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
| 292 | 292 | |
| 293 | - return spip_mysql_query("ALTER " . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 293 | + return spip_mysql_query("ALTER ".$query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * @return bool Toujours true |
| 304 | 304 | */ |
| 305 | 305 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 306 | - spip_mysql_query("OPTIMIZE TABLE " . $table); |
|
| 306 | + spip_mysql_query("OPTIMIZE TABLE ".$table); |
|
| 307 | 307 | |
| 308 | 308 | return true; |
| 309 | 309 | } |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | $link = $connexion['link']; |
| 327 | 327 | $db = $connexion['db']; |
| 328 | 328 | |
| 329 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 329 | + $query = 'EXPLAIN '._mysql_traite_query($query, $db, $prefixe); |
|
| 330 | 330 | $r = mysqli_query($link, $query); |
| 331 | 331 | |
| 332 | 332 | return spip_mysql_fetch($r, null, $serveur); |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | . calculer_mysql_expression('WHERE', $where) |
| 378 | 378 | . calculer_mysql_expression('GROUP BY', $groupby, ',') |
| 379 | 379 | . calculer_mysql_expression('HAVING', $having) |
| 380 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 380 | + . ($orderby ? ("\nORDER BY ".spip_mysql_order($orderby)) : '') |
|
| 381 | 381 | . ($limit ? "\nLIMIT $limit" : ''); |
| 382 | 382 | |
| 383 | 383 | // renvoyer la requete inerte si demandee |
@@ -467,12 +467,12 @@ discard block |
||
| 467 | 467 | $exp = "\n$expression "; |
| 468 | 468 | |
| 469 | 469 | if (!is_array($v)) { |
| 470 | - return $exp . $v; |
|
| 470 | + return $exp.$v; |
|
| 471 | 471 | } else { |
| 472 | 472 | if (strtoupper($join) === 'AND') { |
| 473 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 473 | + return $exp.join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 474 | 474 | } else { |
| 475 | - return $exp . join($join, $v); |
|
| 475 | + return $exp.join($join, $v); |
|
| 476 | 476 | } |
| 477 | 477 | } |
| 478 | 478 | } |
@@ -490,17 +490,17 @@ discard block |
||
| 490 | 490 | if (substr($k, -1) == '@') { |
| 491 | 491 | // c'est une jointure qui se refere au from precedent |
| 492 | 492 | // pas de virgule |
| 493 | - $res .= ' ' . $v; |
|
| 493 | + $res .= ' '.$v; |
|
| 494 | 494 | } else { |
| 495 | 495 | if (!is_numeric($k)) { |
| 496 | 496 | $p = strpos($v, " "); |
| 497 | 497 | if ($p) { |
| 498 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 498 | + $v = substr($v, 0, $p)." AS `$k`".substr($v, $p); |
|
| 499 | 499 | } else { |
| 500 | 500 | $v .= " AS `$k`"; |
| 501 | 501 | } |
| 502 | 502 | } |
| 503 | - $res .= ', ' . $v; |
|
| 503 | + $res .= ', '.$v; |
|
| 504 | 504 | } |
| 505 | 505 | } |
| 506 | 506 | |
@@ -529,13 +529,13 @@ discard block |
||
| 529 | 529 | function _mysql_traite_query($query, $db = '', $prefixe = '') { |
| 530 | 530 | |
| 531 | 531 | if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
| 532 | - $pref = '`' . $db . '`.'; |
|
| 532 | + $pref = '`'.$db.'`.'; |
|
| 533 | 533 | } else { |
| 534 | 534 | $pref = ''; |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | if ($prefixe) { |
| 538 | - $pref .= $prefixe . "_"; |
|
| 538 | + $pref .= $prefixe."_"; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
@@ -549,12 +549,12 @@ discard block |
||
| 549 | 549 | if (stripos($suite, "SELECT") !== false) { |
| 550 | 550 | list($suite, $textes) = query_echappe_textes($suite); |
| 551 | 551 | if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
| 552 | - $suite = $r[1] . _mysql_traite_query($r[2], $db, $prefixe); |
|
| 552 | + $suite = $r[1]._mysql_traite_query($r[2], $db, $prefixe); |
|
| 553 | 553 | } |
| 554 | 554 | $suite = query_reinjecte_textes($suite, $textes); |
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 557 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1'.$pref, $query).$suite; |
|
| 558 | 558 | |
| 559 | 559 | // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
| 560 | 560 | if (defined('_MYSQL_NOPLANES') and _MYSQL_NOPLANES and lire_meta('charset_sql_connexion') == 'utf8') { |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | $link = _mysql_link($serveur); |
| 585 | 585 | $ok = mysqli_select_db($link, $db); |
| 586 | 586 | if (!$ok) { |
| 587 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 587 | + spip_log('Echec mysqli_selectdb. Erreur : '.mysqli_error($link), 'mysql.'._LOG_CRITIQUE); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | return $ok; |
@@ -674,10 +674,10 @@ discard block |
||
| 674 | 674 | |
| 675 | 675 | $character_set = ""; |
| 676 | 676 | if (@$GLOBALS['meta']['charset_sql_base']) { |
| 677 | - $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 677 | + $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 678 | 678 | } |
| 679 | 679 | if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
| 680 | - $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 680 | + $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | foreach ($champs as $k => $v) { |
@@ -686,7 +686,7 @@ discard block |
||
| 686 | 686 | if (preg_match(',(char|text),i', $defs[1]) |
| 687 | 687 | and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
| 688 | 688 | ) { |
| 689 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 689 | + $v = $defs[1].$character_set.' '.substr($v, strlen($defs[1])); |
|
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | 692 | |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | $s = ","; |
| 699 | 699 | } |
| 700 | 700 | $temporary = $temporary ? 'TEMPORARY' : ''; |
| 701 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")" |
|
| 701 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query".($keys ? ",$keys" : '').")" |
|
| 702 | 702 | . " ENGINE=MyISAM" |
| 703 | 703 | . ($character_set ? " DEFAULT $character_set" : "") |
| 704 | 704 | . "\n"; |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | return false; |
| 771 | 771 | } |
| 772 | 772 | |
| 773 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 773 | + $query = "CREATE VIEW $nom AS ".$query_select; |
|
| 774 | 774 | |
| 775 | 775 | return spip_mysql_query($query, $serveur, $requeter); |
| 776 | 776 | } |
@@ -828,7 +828,7 @@ discard block |
||
| 828 | 828 | * Ressource à utiliser avec sql_fetch() |
| 829 | 829 | **/ |
| 830 | 830 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 831 | - return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 831 | + return spip_mysql_query("SHOW TABLES LIKE "._q($match), $serveur, $requeter); |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -922,22 +922,22 @@ discard block |
||
| 922 | 922 | } |
| 923 | 923 | if ($val['Default'] === '0' || $val['Default']) { |
| 924 | 924 | if (preg_match('/[A-Z_]/', $val['Default'])) { |
| 925 | - $nfields[$val["Field"]] .= ' DEFAULT ' . $val['Default']; |
|
| 925 | + $nfields[$val["Field"]] .= ' DEFAULT '.$val['Default']; |
|
| 926 | 926 | } else { |
| 927 | - $nfields[$val["Field"]] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 927 | + $nfields[$val["Field"]] .= " DEFAULT '".$val['Default']."'"; |
|
| 928 | 928 | } |
| 929 | 929 | } |
| 930 | 930 | if ($val['Extra']) { |
| 931 | - $nfields[$val["Field"]] .= ' ' . $val['Extra']; |
|
| 931 | + $nfields[$val["Field"]] .= ' '.$val['Extra']; |
|
| 932 | 932 | } |
| 933 | 933 | if ($val['Key'] == 'PRI') { |
| 934 | 934 | $nkeys['PRIMARY KEY'] = $val["Field"]; |
| 935 | 935 | } else { |
| 936 | 936 | if ($val['Key'] == 'MUL') { |
| 937 | - $nkeys['KEY ' . $val["Field"]] = $val["Field"]; |
|
| 937 | + $nkeys['KEY '.$val["Field"]] = $val["Field"]; |
|
| 938 | 938 | } else { |
| 939 | 939 | if ($val['Key'] == 'UNI') { |
| 940 | - $nkeys['UNIQUE KEY ' . $val["Field"]] = $val["Field"]; |
|
| 940 | + $nkeys['UNIQUE KEY '.$val["Field"]] = $val["Field"]; |
|
| 941 | 941 | } |
| 942 | 942 | } |
| 943 | 943 | } |
@@ -1008,7 +1008,7 @@ discard block |
||
| 1008 | 1008 | $serveur = '', |
| 1009 | 1009 | $requeter = true |
| 1010 | 1010 | ) { |
| 1011 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1011 | + $c = !$groupby ? '*' : ('DISTINCT '.(is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1012 | 1012 | |
| 1013 | 1013 | $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
| 1014 | 1014 | if (!$requeter) { |
@@ -1048,7 +1048,7 @@ discard block |
||
| 1048 | 1048 | if ($s) { |
| 1049 | 1049 | $trace = debug_backtrace(); |
| 1050 | 1050 | if ($trace[0]['function'] != "spip_mysql_error") { |
| 1051 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1051 | + spip_log("$s - $query - ".sql_error_backtrace(), 'mysql.'._LOG_ERREUR); |
|
| 1052 | 1052 | } |
| 1053 | 1053 | } |
| 1054 | 1054 | |
@@ -1206,7 +1206,7 @@ discard block |
||
| 1206 | 1206 | $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | - return spip_mysql_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 1209 | + return spip_mysql_insert($table, "(".join(',', array_keys($couples)).")", "(".join(',', $couples).")", $desc, |
|
| 1210 | 1210 | $serveur, $requeter); |
| 1211 | 1211 | } |
| 1212 | 1212 | |
@@ -1240,7 +1240,7 @@ discard block |
||
| 1240 | 1240 | } |
| 1241 | 1241 | $fields = isset($desc['field']) ? $desc['field'] : array(); |
| 1242 | 1242 | |
| 1243 | - $cles = "(" . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1243 | + $cles = "(".join(',', array_keys(reset($tab_couples))).')'; |
|
| 1244 | 1244 | $valeurs = array(); |
| 1245 | 1245 | $r = false; |
| 1246 | 1246 | |
@@ -1249,7 +1249,7 @@ discard block |
||
| 1249 | 1249 | foreach ($couples as $champ => $val) { |
| 1250 | 1250 | $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
| 1251 | 1251 | } |
| 1252 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1252 | + $valeurs[] = '('.join(',', $couples).')'; |
|
| 1253 | 1253 | if (count($valeurs) >= 100) { |
| 1254 | 1254 | $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
| 1255 | 1255 | $valeurs = array(); |
@@ -1286,7 +1286,7 @@ discard block |
||
| 1286 | 1286 | function spip_mysql_update($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1287 | 1287 | $set = array(); |
| 1288 | 1288 | foreach ($champs as $champ => $val) { |
| 1289 | - $set[] = $champ . "=$val"; |
|
| 1289 | + $set[] = $champ."=$val"; |
|
| 1290 | 1290 | } |
| 1291 | 1291 | if (!empty($set)) { |
| 1292 | 1292 | return spip_mysql_query( |
@@ -1340,7 +1340,7 @@ discard block |
||
| 1340 | 1340 | } |
| 1341 | 1341 | $set = array(); |
| 1342 | 1342 | foreach ($champs as $champ => $val) { |
| 1343 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1343 | + $set[] = $champ.'='.spip_mysql_cite($val, @$fields[$champ]); |
|
| 1344 | 1344 | } |
| 1345 | 1345 | |
| 1346 | 1346 | return spip_mysql_query( |
@@ -1405,8 +1405,8 @@ discard block |
||
| 1405 | 1405 | * - False en cas d'erreur. |
| 1406 | 1406 | **/ |
| 1407 | 1407 | function spip_mysql_replace($table, $couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1408 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',', |
|
| 1409 | - array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1408 | + return spip_mysql_query("REPLACE $table (".join(',', array_keys($couples)).') VALUES ('.join(',', |
|
| 1409 | + array_map('_q', $couples)).')', $serveur, $requeter); |
|
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | |
@@ -1435,10 +1435,10 @@ discard block |
||
| 1435 | 1435 | * - False en cas d'erreur. |
| 1436 | 1436 | **/ |
| 1437 | 1437 | function spip_mysql_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1438 | - $cles = "(" . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1438 | + $cles = "(".join(',', array_keys($tab_couples[0])).')'; |
|
| 1439 | 1439 | $valeurs = array(); |
| 1440 | 1440 | foreach ($tab_couples as $couples) { |
| 1441 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1441 | + $valeurs[] = '('.join(',', array_map('_q', $couples)).')'; |
|
| 1442 | 1442 | } |
| 1443 | 1443 | $valeurs = implode(', ', $valeurs); |
| 1444 | 1444 | |
@@ -1458,28 +1458,28 @@ discard block |
||
| 1458 | 1458 | */ |
| 1459 | 1459 | function spip_mysql_multi($objet, $lang) { |
| 1460 | 1460 | $lengthlang = strlen("[$lang]"); |
| 1461 | - $posmulti = "INSTR(" . $objet . ", '<multi>')"; |
|
| 1462 | - $posfinmulti = "INSTR(" . $objet . ", '</multi>')"; |
|
| 1463 | - $debutchaine = "LEFT(" . $objet . ", $posmulti-1)"; |
|
| 1464 | - $finchaine = "RIGHT(" . $objet . ", CHAR_LENGTH(" . $objet . ") -(7+$posfinmulti))"; |
|
| 1465 | - $chainemulti = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1466 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1461 | + $posmulti = "INSTR(".$objet.", '<multi>')"; |
|
| 1462 | + $posfinmulti = "INSTR(".$objet.", '</multi>')"; |
|
| 1463 | + $debutchaine = "LEFT(".$objet.", $posmulti-1)"; |
|
| 1464 | + $finchaine = "RIGHT(".$objet.", CHAR_LENGTH(".$objet.") -(7+$posfinmulti))"; |
|
| 1465 | + $chainemulti = "TRIM(SUBSTRING(".$objet.", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1466 | + $poslang = "INSTR($chainemulti,'[".$lang."]')"; |
|
| 1467 | 1467 | $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
| 1468 | - $chainelang = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1469 | - $posfinlang = "INSTR(" . $chainelang . ", '[')"; |
|
| 1468 | + $chainelang = "TRIM(SUBSTRING(".$objet.", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1469 | + $posfinlang = "INSTR(".$chainelang.", '[')"; |
|
| 1470 | 1470 | $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
| 1471 | 1471 | //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
| 1472 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1473 | - " TRIM(" . $objet . "), " . |
|
| 1474 | - " CONCAT( " . |
|
| 1475 | - " $debutchaine, " . |
|
| 1476 | - " IF( " . |
|
| 1477 | - " $poslang = 0, " . |
|
| 1478 | - " $chainemulti, " . |
|
| 1479 | - " $chainelang" . |
|
| 1480 | - " ), " . |
|
| 1481 | - " $finchaine" . |
|
| 1482 | - " ) " . |
|
| 1472 | + $retour = "(TRIM(IF($posmulti = 0 , ". |
|
| 1473 | + " TRIM(".$objet."), ". |
|
| 1474 | + " CONCAT( ". |
|
| 1475 | + " $debutchaine, ". |
|
| 1476 | + " IF( ". |
|
| 1477 | + " $poslang = 0, ". |
|
| 1478 | + " $chainemulti, ". |
|
| 1479 | + " $chainelang". |
|
| 1480 | + " ), ". |
|
| 1481 | + " $finchaine". |
|
| 1482 | + " ) ". |
|
| 1483 | 1483 | "))) AS multi"; |
| 1484 | 1484 | |
| 1485 | 1485 | return $retour; |
@@ -1496,7 +1496,7 @@ discard block |
||
| 1496 | 1496 | * Valeur hexadécimale pour MySQL |
| 1497 | 1497 | **/ |
| 1498 | 1498 | function spip_mysql_hex($v) { |
| 1499 | - return "0x" . $v; |
|
| 1499 | + return "0x".$v; |
|
| 1500 | 1500 | } |
| 1501 | 1501 | |
| 1502 | 1502 | /** |
@@ -1581,9 +1581,9 @@ discard block |
||
| 1581 | 1581 | $in_sql = ""; |
| 1582 | 1582 | while ($n = strpos($valeurs, ',', $n + 1)) { |
| 1583 | 1583 | if ((++$i) >= 255) { |
| 1584 | - $in_sql .= "($val $not IN (" . |
|
| 1585 | - substr($valeurs, 0, $n) . |
|
| 1586 | - "))\n" . |
|
| 1584 | + $in_sql .= "($val $not IN (". |
|
| 1585 | + substr($valeurs, 0, $n). |
|
| 1586 | + "))\n". |
|
| 1587 | 1587 | ($not ? "AND\t" : "OR\t"); |
| 1588 | 1588 | $valeurs = substr($valeurs, $n + 1); |
| 1589 | 1589 | $i = $n = 0; |
@@ -1648,7 +1648,7 @@ discard block |
||
| 1648 | 1648 | } |
| 1649 | 1649 | } |
| 1650 | 1650 | |
| 1651 | - return ("'" . addslashes($v) . "'"); |
|
| 1651 | + return ("'".addslashes($v)."'"); |
|
| 1652 | 1652 | } |
| 1653 | 1653 | |
| 1654 | 1654 | |
@@ -1677,9 +1677,9 @@ discard block |
||
| 1677 | 1677 | $connexion = &$GLOBALS['connexions'][0]; |
| 1678 | 1678 | $bd = $connexion['db']; |
| 1679 | 1679 | $prefixe = $connexion['prefixe']; |
| 1680 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1680 | + $nom = "$bd:$prefixe:$nom"._LOCK_TIME; |
|
| 1681 | 1681 | |
| 1682 | - $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1682 | + $connexion['last'] = $q = "SELECT GET_LOCK("._q($nom).", $timeout) AS n"; |
|
| 1683 | 1683 | |
| 1684 | 1684 | $q = @sql_fetch(mysqli_query(_mysql_link(), $q)); |
| 1685 | 1685 | if (!$q) { |
@@ -1706,9 +1706,9 @@ discard block |
||
| 1706 | 1706 | $connexion = &$GLOBALS['connexions'][0]; |
| 1707 | 1707 | $bd = $connexion['db']; |
| 1708 | 1708 | $prefixe = $connexion['prefixe']; |
| 1709 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1709 | + $nom = "$bd:$prefixe:$nom"._LOCK_TIME; |
|
| 1710 | 1710 | |
| 1711 | - $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1711 | + $connexion['last'] = $q = "SELECT RELEASE_LOCK("._q($nom).")"; |
|
| 1712 | 1712 | mysqli_query(_mysql_link(), $q); |
| 1713 | 1713 | } |
| 1714 | 1714 | |
@@ -1744,7 +1744,7 @@ discard block |
||
| 1744 | 1744 | } else { |
| 1745 | 1745 | $GLOBALS['mysql_rappel_nom_base'] = false; |
| 1746 | 1746 | |
| 1747 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1747 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; ". |
|
| 1748 | 1748 | "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
| 1749 | 1749 | } |
| 1750 | 1750 | } |