@@ -21,23 +21,23 @@ |
||
| 21 | 21 | |
| 22 | 22 | define('_SUB_REGEXP_SYMBOL', '[\w_:.-]'); |
| 23 | 23 | |
| 24 | -define('_REGEXP_NMTOKEN', '/^' . _SUB_REGEXP_SYMBOL . '+$/'); |
|
| 24 | +define('_REGEXP_NMTOKEN', '/^'._SUB_REGEXP_SYMBOL.'+$/'); |
|
| 25 | 25 | |
| 26 | -define('_REGEXP_NMTOKENS', '/^(' . _SUB_REGEXP_SYMBOL . '+\s*)*$/'); |
|
| 26 | +define('_REGEXP_NMTOKENS', '/^('._SUB_REGEXP_SYMBOL.'+\s*)*$/'); |
|
| 27 | 27 | |
| 28 | -define('_REGEXP_ID', '/^[A-Za-z_:]' . _SUB_REGEXP_SYMBOL . '*$/'); |
|
| 28 | +define('_REGEXP_ID', '/^[A-Za-z_:]'._SUB_REGEXP_SYMBOL.'*$/'); |
|
| 29 | 29 | |
| 30 | -define('_REGEXP_ENTITY_USE', '/%(' . _SUB_REGEXP_SYMBOL . '+);/'); |
|
| 31 | -define('_REGEXP_ENTITY_DEF', '/^%(' . _SUB_REGEXP_SYMBOL . '+);/'); |
|
| 30 | +define('_REGEXP_ENTITY_USE', '/%('._SUB_REGEXP_SYMBOL.'+);/'); |
|
| 31 | +define('_REGEXP_ENTITY_DEF', '/^%('._SUB_REGEXP_SYMBOL.'+);/'); |
|
| 32 | 32 | define('_REGEXP_TYPE_XML', 'PUBLIC|SYSTEM|INCLUDE|IGNORE|CDATA'); |
| 33 | -define('_REGEXP_ENTITY_DECL', '/^<!ENTITY\s+(%?)\s*(' . |
|
| 34 | - _SUB_REGEXP_SYMBOL . |
|
| 35 | - '+;?)\s+(' . |
|
| 36 | - _REGEXP_TYPE_XML . |
|
| 37 | - ')?\s*(' . |
|
| 38 | - "('([^']*)')" . |
|
| 39 | - '|("([^"]*)")' . |
|
| 40 | - '|\s*(%' . _SUB_REGEXP_SYMBOL . '+;)\s*' . |
|
| 33 | +define('_REGEXP_ENTITY_DECL', '/^<!ENTITY\s+(%?)\s*('. |
|
| 34 | + _SUB_REGEXP_SYMBOL. |
|
| 35 | + '+;?)\s+('. |
|
| 36 | + _REGEXP_TYPE_XML. |
|
| 37 | + ')?\s*('. |
|
| 38 | + "('([^']*)')". |
|
| 39 | + '|("([^"]*)")'. |
|
| 40 | + '|\s*(%'._SUB_REGEXP_SYMBOL.'+;)\s*'. |
|
| 41 | 41 | ')\s*(--.*?--)?("([^"]*)")?\s*>\s*(.*)$/s'); |
| 42 | 42 | |
| 43 | 43 | define('_REGEXP_INCLUDE_USE', '/^<!\[\s*%\s*([^;]*);\s*\[\s*(.*)$/s'); |
@@ -61,12 +61,12 @@ discard block |
||
| 61 | 61 | * |
| 62 | 62 | * |
| 63 | 63 | **/ |
| 64 | -function base_trouver_table_dist($nom, $serveur='', $table_spip = true){ |
|
| 65 | - static $nom_cache_desc_sql=array(); |
|
| 64 | +function base_trouver_table_dist($nom, $serveur = '', $table_spip = true) { |
|
| 65 | + static $nom_cache_desc_sql = array(); |
|
| 66 | 66 | global $tables_principales, $tables_auxiliaires, $table_des_tables; |
| 67 | 67 | |
| 68 | 68 | if (!spip_connect($serveur) |
| 69 | - OR !preg_match('/^[a-zA-Z0-9._-]*/',$nom)) |
|
| 69 | + OR !preg_match('/^[a-zA-Z0-9._-]*/', $nom)) |
|
| 70 | 70 | return null; |
| 71 | 71 | |
| 72 | 72 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
@@ -75,18 +75,18 @@ discard block |
||
| 75 | 75 | // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
| 76 | 76 | // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
| 77 | 77 | // de connexion, et tout risque d'ambiguite |
| 78 | - if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])){ |
|
| 78 | + if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 79 | 79 | $nom_cache_desc_sql[$serveur][$objets_sql] = |
| 80 | - _DIR_CACHE . 'sql_desc_' |
|
| 81 | - . ($serveur ? "{$serveur}_":"") |
|
| 82 | - . substr(md5($connexion['db'].":".$connexion['prefixe'].":$objets_sql"),0,8) |
|
| 80 | + _DIR_CACHE.'sql_desc_' |
|
| 81 | + . ($serveur ? "{$serveur}_" : "") |
|
| 82 | + . substr(md5($connexion['db'].":".$connexion['prefixe'].":$objets_sql"), 0, 8) |
|
| 83 | 83 | .'.txt'; |
| 84 | 84 | // nouveau nom de cache = nouvelle version en memoire |
| 85 | 85 | unset($connexion['tables']); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
| 89 | - if (!$nom){ |
|
| 89 | + if (!$nom) { |
|
| 90 | 90 | spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
| 91 | 91 | $connexion['tables'] = array(); |
| 92 | 92 | return null; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | if ($connexion['spip_connect_version']) { |
| 106 | 106 | if ($table_spip AND isset($table_des_tables[$nom])) { |
| 107 | 107 | $nom = $table_des_tables[$nom]; |
| 108 | - $nom_sql = 'spip_' . $nom; |
|
| 108 | + $nom_sql = 'spip_'.$nom; |
|
| 109 | 109 | } |
| 110 | 110 | } |
| 111 | 111 | |
@@ -114,10 +114,10 @@ discard block |
||
| 114 | 114 | // on essaye de recharger le cache des decriptions de ce serveur |
| 115 | 115 | // dans le fichier cache |
| 116 | 116 | if (!isset($connexion['tables'][$nom_sql]) |
| 117 | - AND defined('_VAR_MODE') AND _VAR_MODE!=='recalcul' |
|
| 117 | + AND defined('_VAR_MODE') AND _VAR_MODE !== 'recalcul' |
|
| 118 | 118 | AND (!isset($connexion['tables']) OR !$connexion['tables'])) { |
| 119 | - if (lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql],$desc_cache) |
|
| 120 | - AND $desc_cache=unserialize($desc_cache)) |
|
| 119 | + if (lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 120 | + AND $desc_cache = unserialize($desc_cache)) |
|
| 121 | 121 | $connexion['tables'] = $desc_cache; |
| 122 | 122 | } |
| 123 | 123 | if ($table_spip AND !isset($connexion['tables'][$nom_sql])) { |
@@ -127,12 +127,12 @@ discard block |
||
| 127 | 127 | // meme si pas d'abreviation declaree, trouver la table spip_$nom |
| 128 | 128 | // si c'est une table principale, |
| 129 | 129 | // puisqu'on le fait aussi pour les tables auxiliaires |
| 130 | - elseif ($nom_sql==$nom AND isset($tables_principales['spip_' .$nom])){ |
|
| 131 | - $nom_sql = 'spip_' . $nom; |
|
| 130 | + elseif ($nom_sql == $nom AND isset($tables_principales['spip_'.$nom])) { |
|
| 131 | + $nom_sql = 'spip_'.$nom; |
|
| 132 | 132 | $fdesc = &$tables_principales[$nom_sql]; |
| 133 | 133 | } |
| 134 | - elseif (isset($tables_auxiliaires[$n=$nom]) |
|
| 135 | - OR isset($tables_auxiliaires[$n='spip_'.$nom])) { |
|
| 134 | + elseif (isset($tables_auxiliaires[$n = $nom]) |
|
| 135 | + OR isset($tables_auxiliaires[$n = 'spip_'.$nom])) { |
|
| 136 | 136 | $nom_sql = $n; |
| 137 | 137 | $fdesc = &$tables_auxiliaires[$n]; |
| 138 | 138 | } # table locale a cote de SPIP, comme non SPIP: |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $desc = sql_showtable($nom_sql, $table_spip, $serveur); |
| 144 | 144 | if (!$desc OR !$desc['field']) { |
| 145 | 145 | if (!$fdesc) { |
| 146 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'",_LOG_INFO_IMPORTANTE); |
|
| 146 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", _LOG_INFO_IMPORTANTE); |
|
| 147 | 147 | return null; |
| 148 | 148 | } |
| 149 | 149 | // on ne sait pas lire la structure de la table : |
@@ -155,12 +155,12 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | $desc['table'] = $desc['table_sql'] = $nom_sql; |
| 158 | - $desc['connexion']= $serveur; |
|
| 158 | + $desc['connexion'] = $serveur; |
|
| 159 | 159 | |
| 160 | 160 | // charger les infos declarees pour cette table |
| 161 | 161 | // en lui passant les infos connues |
| 162 | 162 | // $desc est prioritaire pour la description de la table |
| 163 | - $desc = array_merge(lister_tables_objets_sql($nom_sql,$desc),$desc); |
|
| 163 | + $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 164 | 164 | |
| 165 | 165 | // si tables_objets_sql est bien fini d'init, on peut cacher |
| 166 | 166 | $connexion['tables'][$nom_sql] = $desc; |
@@ -168,13 +168,13 @@ discard block |
||
| 168 | 168 | // une nouvelle table a ete decrite |
| 169 | 169 | // mettons donc a jour le cache des descriptions de ce serveur |
| 170 | 170 | if (is_writeable(_DIR_CACHE)) |
| 171 | - ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql],serialize($connexion['tables']),true); |
|
| 171 | + ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 172 | 172 | } |
| 173 | 173 | else |
| 174 | 174 | $res = &$connexion['tables'][$nom_sql]; |
| 175 | 175 | |
| 176 | 176 | // toujours retourner $nom dans id_table |
| 177 | - $res['id_table']=$nom; |
|
| 177 | + $res['id_table'] = $nom; |
|
| 178 | 178 | |
| 179 | 179 | return $res; |
| 180 | 180 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) return; |
| 14 | -require_once _ROOT_RESTREINT . 'base/objets.php'; |
|
| 14 | +require_once _ROOT_RESTREINT.'base/objets.php'; |
|
| 15 | 15 | |
| 16 | 16 | // |
| 17 | 17 | // Utilitaires indispensables autour des serveurs SQL |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | // A l'installation, il faut simuler l'existence de ce fichier |
| 26 | 26 | |
| 27 | 27 | // http://doc.spip.org/@spip_connect |
| 28 | -function spip_connect($serveur='', $version='') { |
|
| 28 | +function spip_connect($serveur = '', $version = '') { |
|
| 29 | 29 | global $connexions, $spip_sql_version; |
| 30 | 30 | |
| 31 | 31 | $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
| 42 | 42 | ? '' // nom de serveur mal ecrit |
| 43 | 43 | : ($serveur ? |
| 44 | - ( _DIR_CONNECT. $serveur . '.php') // serveur externe |
|
| 44 | + (_DIR_CONNECT.$serveur.'.php') // serveur externe |
|
| 45 | 45 | : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok |
| 46 | 46 | : ($install ? _FILE_CONNECT_TMP // init du serveur principal |
| 47 | 47 | : ''))); // installation pas faite |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | // chercher une declaration de serveur dans le path |
| 56 | 56 | // qui pourra un jour servir a declarer des bases sqlite |
| 57 | 57 | // par des plugins. Et sert aussi aux boucles POUR. |
| 58 | - find_in_path("$serveur.php",'connect/',true); |
|
| 58 | + find_in_path("$serveur.php", 'connect/', true); |
|
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | if (!isset($GLOBALS['db_ok'])) { |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
| 68 | 68 | spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
| 69 | 69 | // ne plus reessayer si ce n'est pas l'install |
| 70 | - return $connexions[$index]=false; |
|
| 70 | + return $connexions[$index] = false; |
|
| 71 | 71 | } |
| 72 | 72 | $connexions[$index] = $GLOBALS['db_ok']; |
| 73 | 73 | } |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | // chargement de la version du jeu de fonctions |
| 79 | 79 | // si pas dans le fichier par defaut |
| 80 | 80 | $type = $GLOBALS['db_ok']['type']; |
| 81 | - $jeu = 'spip_' . $type .'_functions_' . $version; |
|
| 81 | + $jeu = 'spip_'.$type.'_functions_'.$version; |
|
| 82 | 82 | if (!isset($GLOBALS[$jeu])) { |
| 83 | - if (!find_in_path($type . '_' . $version . '.php', 'req/', true)){ |
|
| 83 | + if (!find_in_path($type.'_'.$version.'.php', 'req/', true)) { |
|
| 84 | 84 | spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
| 85 | 85 | // ne plus reessayer |
| 86 | 86 | return $connexions[$index][$version] = array(); |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT); |
| 104 | 104 | return false; |
| 105 | 105 | } |
| 106 | - } else { |
|
| 106 | + } else { |
|
| 107 | 107 | // spip_meta n'existe pas toujours dans la base |
| 108 | 108 | // C'est le cas d'un dump sqlite par exemple |
| 109 | 109 | if ($connexions[$index]['spip_connect_version'] |
| 110 | 110 | AND sql_showtable('spip_meta', true, $serveur) |
| 111 | - AND $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'",'','','','',$serveur)) |
|
| 111 | + AND $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)) |
|
| 112 | 112 | $charset = $r; |
| 113 | 113 | else $charset = -1; |
| 114 | 114 | } |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | return $connexions[$index]; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | -function spip_sql_erreur($serveur='') |
|
| 123 | +function spip_sql_erreur($serveur = '') |
|
| 124 | 124 | { |
| 125 | 125 | $connexion = spip_connect($serveur); |
| 126 | 126 | $e = sql_errno($serveur); |
| 127 | 127 | $t = (isset($connexion['type']) ? $connexion['type'] : 'sql'); |
| 128 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\n" . $connexion['last']; |
|
| 129 | - $f = $t . $serveur; |
|
| 128 | + $m = "Erreur $e de $t: ".sql_error($serveur)."\n".$connexion['last']; |
|
| 129 | + $f = $t.$serveur; |
|
| 130 | 130 | spip_log($m, $f.'.'._LOG_ERREUR); |
| 131 | 131 | } |
| 132 | 132 | |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | // connue seulement des convertisseurs automatiques |
| 137 | 137 | |
| 138 | 138 | // http://doc.spip.org/@spip_connect_sql |
| 139 | -function spip_connect_sql($version, $ins='', $serveur='', $cont=false) { |
|
| 139 | +function spip_connect_sql($version, $ins = '', $serveur = '', $cont = false) { |
|
| 140 | 140 | $desc = spip_connect($serveur, $version); |
| 141 | 141 | if (function_exists($f = @$desc[$version][$ins])) return $f; |
| 142 | 142 | if ($cont) return $desc; |
@@ -166,28 +166,28 @@ discard block |
||
| 166 | 166 | * @param string $auth |
| 167 | 167 | * @return array |
| 168 | 168 | */ |
| 169 | -function spip_connect_db($host, $port, $login, $pass, $db='', $type='mysql', $prefixe='', $auth='') { |
|
| 169 | +function spip_connect_db($host, $port, $login, $pass, $db = '', $type = 'mysql', $prefixe = '', $auth = '') { |
|
| 170 | 170 | global $db_ok; |
| 171 | 171 | |
| 172 | 172 | // temps avant nouvelle tentative de connexion |
| 173 | 173 | // suite a une connection echouee |
| 174 | 174 | if (!defined('_CONNECT_RETRY_DELAY')) |
| 175 | - define('_CONNECT_RETRY_DELAY',30); |
|
| 175 | + define('_CONNECT_RETRY_DELAY', 30); |
|
| 176 | 176 | |
| 177 | 177 | $f = ""; |
| 178 | 178 | // un fichier de identifiant par combinaison (type,host,port,db) |
| 179 | 179 | // pour ne pas declarer tout indisponible d'un coup |
| 180 | 180 | // si en cours d'installation ou si db=@test@ on ne pose rien |
| 181 | 181 | // car c'est un test de connexion |
| 182 | - if (!defined('_ECRIRE_INSTALL') AND !$db=="@test@") |
|
| 183 | - $f = _DIR_TMP . $type . '.' . substr(md5($host.$port.$db),0,8) . '.out'; |
|
| 184 | - elseif ($db=='@test@') |
|
| 182 | + if (!defined('_ECRIRE_INSTALL') AND !$db == "@test@") |
|
| 183 | + $f = _DIR_TMP.$type.'.'.substr(md5($host.$port.$db), 0, 8).'.out'; |
|
| 184 | + elseif ($db == '@test@') |
|
| 185 | 185 | $db = ''; |
| 186 | 186 | |
| 187 | 187 | if ($f |
| 188 | 188 | AND @file_exists($f) |
| 189 | 189 | AND (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)) { |
| 190 | - spip_log( "Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 190 | + spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 191 | 191 | return; |
| 192 | 192 | } |
| 193 | 193 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | ? $GLOBALS['table_prefix'] : $db; |
| 197 | 197 | $h = charger_fonction($type, 'req', true); |
| 198 | 198 | if (!$h) { |
| 199 | - spip_log( "les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 199 | + spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 200 | 200 | return; |
| 201 | 201 | } |
| 202 | 202 | if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | // En cas d'indisponibilite du serveur, eviter de le bombarder |
| 214 | 214 | if ($f) { |
| 215 | 215 | @touch($f); |
| 216 | - spip_log( "Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS); |
|
| 216 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type.'.'._LOG_HS); |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | |
@@ -233,14 +233,14 @@ discard block |
||
| 233 | 233 | // http://doc.spip.org/@spip_connect_main |
| 234 | 234 | function spip_connect_main($connexion) |
| 235 | 235 | { |
| 236 | - if ($GLOBALS['spip_connect_version']< 0.1 AND _DIR_RESTREINT){ |
|
| 236 | + if ($GLOBALS['spip_connect_version'] < 0.1 AND _DIR_RESTREINT) { |
|
| 237 | 237 | include_spip('inc/headers'); |
| 238 | 238 | redirige_url_ecrire('upgrade', 'reinstall=oui'); |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | if (!($f = $connexion['select'])) return false; |
| 242 | 242 | // en cas d'erreur select retourne la requette (is_string=true donc) |
| 243 | - if (!$r = $f('valeur','spip_meta', "nom='charset_sql_connexion'") |
|
| 243 | + if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 244 | 244 | OR is_string($r)) |
| 245 | 245 | return false; |
| 246 | 246 | if (!($f = $connexion['fetch'])) return false; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | // compatibilite |
| 252 | -function spip_connect_ldap($serveur='') { |
|
| 252 | +function spip_connect_ldap($serveur = '') { |
|
| 253 | 253 | include_spip('auth/ldap'); |
| 254 | 254 | return auth_ldap_connect($serveur); |
| 255 | 255 | } |
@@ -258,9 +258,8 @@ discard block |
||
| 258 | 258 | // pour un array(1,'a',"a'") renvoie la chaine "'1','a','a\''" |
| 259 | 259 | // Usage sql un peu deprecie, a remplacer par sql_quote() |
| 260 | 260 | // http://doc.spip.org/@_q |
| 261 | -function _q ($a) { |
|
| 262 | - return (is_numeric($a)) ? strval($a) : |
|
| 263 | - (!is_array($a) ? ("'" . addslashes($a) . "'") |
|
| 261 | +function _q($a) { |
|
| 262 | + return (is_numeric($a)) ? strval($a) : (!is_array($a) ? ("'".addslashes($a)."'") |
|
| 264 | 263 | : join(",", array_map('_q', $a))); |
| 265 | 264 | } |
| 266 | 265 | |
@@ -287,25 +286,25 @@ discard block |
||
| 287 | 286 | * @param string $query |
| 288 | 287 | * @return array |
| 289 | 288 | */ |
| 290 | -function query_echappe_textes($query){ |
|
| 289 | +function query_echappe_textes($query) { |
|
| 291 | 290 | static $codeEchappements = array("''"=>"\x1@##@\x1", "\'"=>"\x2@##@\x2", "\\\""=>"\x3@##@\x3"); |
| 292 | 291 | $query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
| 293 | - if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S",$query,$textes)){ |
|
| 292 | + if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) { |
|
| 294 | 293 | $textes = reset($textes); // indice 0 du match |
| 295 | - switch(count($textes)){ |
|
| 296 | - case 0:$replace=array();break; |
|
| 297 | - case 1:$replace=array('%1$s');break; |
|
| 298 | - case 2:$replace=array('%1$s','%2$s');break; |
|
| 299 | - case 3:$replace=array('%1$s','%2$s','%3$s');break; |
|
| 300 | - case 4:$replace=array('%1$s','%2$s','%3$s','%4$s');break; |
|
| 301 | - case 5:$replace=array('%1$s','%2$s','%3$s','%4$s','%5$s');break; |
|
| 294 | + switch (count($textes)) { |
|
| 295 | + case 0:$replace = array(); break; |
|
| 296 | + case 1:$replace = array('%1$s'); break; |
|
| 297 | + case 2:$replace = array('%1$s', '%2$s'); break; |
|
| 298 | + case 3:$replace = array('%1$s', '%2$s', '%3$s'); break; |
|
| 299 | + case 4:$replace = array('%1$s', '%2$s', '%3$s', '%4$s'); break; |
|
| 300 | + case 5:$replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s'); break; |
|
| 302 | 301 | default: |
| 303 | - $replace = range(1,count($textes)); |
|
| 304 | - $replace = '%'.implode('$s,%',$replace).'$s'; |
|
| 305 | - $replace = explode(',',$replace); |
|
| 302 | + $replace = range(1, count($textes)); |
|
| 303 | + $replace = '%'.implode('$s,%', $replace).'$s'; |
|
| 304 | + $replace = explode(',', $replace); |
|
| 306 | 305 | break; |
| 307 | 306 | } |
| 308 | - $query = str_replace($textes,$replace,$query); |
|
| 307 | + $query = str_replace($textes, $replace, $query); |
|
| 309 | 308 | } |
| 310 | 309 | else |
| 311 | 310 | $textes = array(); |
@@ -321,7 +320,7 @@ discard block |
||
| 321 | 320 | * @param array $textes |
| 322 | 321 | * @return string |
| 323 | 322 | */ |
| 324 | -function query_reinjecte_textes($query, $textes){ |
|
| 323 | +function query_reinjecte_textes($query, $textes) { |
|
| 325 | 324 | static $codeEchappements = array("''"=>"\x1@##@\x1", "\'"=>"\x2@##@\x2", "\\\""=>"\x3@##@\x3"); |
| 326 | 325 | # debug de la substitution |
| 327 | 326 | #if (($c1=substr_count($query,"%"))!=($c2=count($textes))){ |
@@ -329,16 +328,16 @@ discard block |
||
| 329 | 328 | # spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR); |
| 330 | 329 | # spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR); |
| 331 | 330 | #} |
| 332 | - switch (count($textes)){ |
|
| 331 | + switch (count($textes)) { |
|
| 333 | 332 | case 0:break; |
| 334 | - case 1:$query=sprintf($query,$textes[0]);break; |
|
| 335 | - case 2:$query=sprintf($query,$textes[0],$textes[1]);break; |
|
| 336 | - case 3:$query=sprintf($query,$textes[0],$textes[1],$textes[2]);break; |
|
| 337 | - case 4:$query=sprintf($query,$textes[0],$textes[1],$textes[2],$textes[3]);break; |
|
| 338 | - case 5:$query=sprintf($query,$textes[0],$textes[1],$textes[2],$textes[3],$textes[4]);break; |
|
| 333 | + case 1:$query = sprintf($query, $textes[0]); break; |
|
| 334 | + case 2:$query = sprintf($query, $textes[0], $textes[1]); break; |
|
| 335 | + case 3:$query = sprintf($query, $textes[0], $textes[1], $textes[2]); break; |
|
| 336 | + case 4:$query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]); break; |
|
| 337 | + case 5:$query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]); break; |
|
| 339 | 338 | default: |
| 340 | - array_unshift($textes,$query); |
|
| 341 | - $query = call_user_func_array('sprintf',$textes); |
|
| 339 | + array_unshift($textes, $query); |
|
| 340 | + $query = call_user_func_array('sprintf', $textes); |
|
| 342 | 341 | break; |
| 343 | 342 | } |
| 344 | 343 | |
@@ -349,7 +348,7 @@ discard block |
||
| 349 | 348 | |
| 350 | 349 | // Pour compatibilite. Ne plus utiliser. |
| 351 | 350 | // http://doc.spip.org/@spip_query |
| 352 | -function spip_query($query, $serveur='') { |
|
| 351 | +function spip_query($query, $serveur = '') { |
|
| 353 | 352 | global $spip_sql_version; |
| 354 | 353 | $f = spip_connect_sql($spip_sql_version, 'query', $serveur, true); |
| 355 | 354 | return function_exists($f) ? $f($query, $serveur) : false; |
@@ -52,9 +52,9 @@ discard block |
||
| 52 | 52 | * Si l'instruction demandee n'existe pas, retourne la liste de toutes les instructions du serveur SQL avec $continue a true. |
| 53 | 53 | * |
| 54 | 54 | **/ |
| 55 | -function sql_serveur($ins_sql='', $serveur='', $continue=false) { |
|
| 55 | +function sql_serveur($ins_sql = '', $serveur = '', $continue = false) { |
|
| 56 | 56 | static $sql_serveur = array(); |
| 57 | - if (!isset($sql_serveur[$serveur][$ins_sql])){ |
|
| 57 | + if (!isset($sql_serveur[$serveur][$ins_sql])) { |
|
| 58 | 58 | $f = spip_connect_sql(sql_ABSTRACT_VERSION, $ins_sql, $serveur, $continue); |
| 59 | 59 | if (!is_string($f) OR !$f) return $f; |
| 60 | 60 | $sql_serveur[$serveur][$ins_sql] = $f; |
@@ -80,16 +80,16 @@ discard block |
||
| 80 | 80 | * @return string|bool |
| 81 | 81 | * Retourne le nom du charset si effectivement trouve, sinon false. |
| 82 | 82 | **/ |
| 83 | -function sql_get_charset($charset, $serveur='', $option=true){ |
|
| 83 | +function sql_get_charset($charset, $serveur = '', $option = true) { |
|
| 84 | 84 | // le nom http du charset differe parfois du nom SQL utf-8 ==> utf8 etc. |
| 85 | - $desc = sql_serveur('', $serveur, true,true); |
|
| 85 | + $desc = sql_serveur('', $serveur, true, true); |
|
| 86 | 86 | $desc = $desc[sql_ABSTRACT_VERSION]; |
| 87 | 87 | $c = $desc['charsets'][$charset]; |
| 88 | 88 | if ($c) { |
| 89 | - if (function_exists($f=@$desc['get_charset'])) |
|
| 90 | - if ($f($c, $serveur, $option!==false)) return $c; |
|
| 89 | + if (function_exists($f = @$desc['get_charset'])) |
|
| 90 | + if ($f($c, $serveur, $option !== false)) return $c; |
|
| 91 | 91 | } |
| 92 | - spip_log( "SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", _LOG_AVERTISSEMENT); |
|
| 92 | + spip_log("SPIP ne connait pas les Charsets disponibles sur le serveur $serveur. Le serveur choisira seul.", _LOG_AVERTISSEMENT); |
|
| 93 | 93 | return false; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | * @return bool |
| 116 | 116 | * Retourne true si elle reussie. |
| 117 | 117 | **/ |
| 118 | -function sql_set_charset($charset,$serveur='', $option=true){ |
|
| 119 | - $f = sql_serveur('set_charset', $serveur, $option==='continue' OR $option===false); |
|
| 118 | +function sql_set_charset($charset, $serveur = '', $option = true) { |
|
| 119 | + $f = sql_serveur('set_charset', $serveur, $option === 'continue' OR $option === false); |
|
| 120 | 120 | if (!is_string($f) OR !$f) return false; |
| 121 | - return $f($charset, $serveur, $option!==false); |
|
| 121 | + return $f($charset, $serveur, $option !== false); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | * afin de disposer du texte brut. |
| 168 | 168 | * |
| 169 | 169 | **/ |
| 170 | -function sql_select ($select = array(), $from = array(), $where = array(), |
|
| 170 | +function sql_select($select = array(), $from = array(), $where = array(), |
|
| 171 | 171 | $groupby = array(), $orderby = array(), $limit = '', $having = array(), |
| 172 | - $serveur='', $option=true) { |
|
| 173 | - $f = sql_serveur('select', $serveur, $option==='continue' OR $option===false); |
|
| 172 | + $serveur = '', $option = true) { |
|
| 173 | + $f = sql_serveur('select', $serveur, $option === 'continue' OR $option === false); |
|
| 174 | 174 | if (!is_string($f) OR !$f) return false; |
| 175 | 175 | |
| 176 | 176 | $debug = (defined('_VAR_MODE') AND _VAR_MODE == 'debug'); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | // le debug, c'est pour ce qui a ete produit par le compilateur |
| 183 | 183 | if (isset($GLOBALS['debug']['aucasou'])) { |
| 184 | 184 | list($table, $id,) = $GLOBALS['debug']['aucasou']; |
| 185 | - $nom = $GLOBALS['debug_objets']['courant'] . $id; |
|
| 185 | + $nom = $GLOBALS['debug_objets']['courant'].$id; |
|
| 186 | 186 | $GLOBALS['debug_objets']['requete'][$nom] = $query; |
| 187 | 187 | } |
| 188 | 188 | $res = $f($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, true); |
@@ -232,8 +232,8 @@ discard block |
||
| 232 | 232 | **/ |
| 233 | 233 | function sql_get_select($select = array(), $from = array(), $where = array(), |
| 234 | 234 | $groupby = array(), $orderby = array(), $limit = '', $having = array(), |
| 235 | - $serveur='') { |
|
| 236 | - return sql_select ($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 235 | + $serveur = '') { |
|
| 236 | + return sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, false); |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | |
@@ -268,11 +268,11 @@ discard block |
||
| 268 | 268 | **/ |
| 269 | 269 | function sql_countsel($from = array(), $where = array(), |
| 270 | 270 | $groupby = array(), $having = array(), |
| 271 | - $serveur='', $option=true) { |
|
| 272 | - $f = sql_serveur('countsel', $serveur, $option==='continue' OR $option===false); |
|
| 271 | + $serveur = '', $option = true) { |
|
| 272 | + $f = sql_serveur('countsel', $serveur, $option === 'continue' OR $option === false); |
|
| 273 | 273 | if (!is_string($f) OR !$f) return false; |
| 274 | - $r = $f($from, $where, $groupby, $having, $serveur, $option!==false); |
|
| 275 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 274 | + $r = $f($from, $where, $groupby, $having, $serveur, $option !== false); |
|
| 275 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 276 | 276 | return $r; |
| 277 | 277 | } |
| 278 | 278 | |
@@ -299,11 +299,11 @@ discard block |
||
| 299 | 299 | * - false en cas de serveur indiponible ou d'erreur |
| 300 | 300 | * Ce retour n'est pas pertinent pour savoir si l'operation est correctement realisee. |
| 301 | 301 | **/ |
| 302 | -function sql_alter($q, $serveur='', $option=true) { |
|
| 303 | - $f = sql_serveur('alter', $serveur, $option==='continue' OR $option===false); |
|
| 302 | +function sql_alter($q, $serveur = '', $option = true) { |
|
| 303 | + $f = sql_serveur('alter', $serveur, $option === 'continue' OR $option === false); |
|
| 304 | 304 | if (!is_string($f) OR !$f) return false; |
| 305 | - $r = $f($q, $serveur, $option!==false); |
|
| 306 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 305 | + $r = $f($q, $serveur, $option !== false); |
|
| 306 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 307 | 307 | return $r; |
| 308 | 308 | } |
| 309 | 309 | |
@@ -326,10 +326,10 @@ discard block |
||
| 326 | 326 | * Tableau de cles (colonnes SQL ou alias) / valeurs (valeurs dans la colonne de la table ou calculee) |
| 327 | 327 | * presentant une ligne de resultat d'une selection |
| 328 | 328 | */ |
| 329 | -function sql_fetch($res, $serveur='', $option=true) { |
|
| 330 | - $f = sql_serveur('fetch', $serveur, $option==='continue' OR $option===false); |
|
| 329 | +function sql_fetch($res, $serveur = '', $option = true) { |
|
| 330 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' OR $option === false); |
|
| 331 | 331 | if (!is_string($f) OR !$f) return false; |
| 332 | - return $f($res, NULL, $serveur, $option!==false); |
|
| 332 | + return $f($res, NULL, $serveur, $option !== false); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | |
@@ -355,12 +355,12 @@ discard block |
||
| 355 | 355 | * de cles (colonnes SQL ou alias) / valeurs (valeurs dans la colonne de la table ou calculee) |
| 356 | 356 | * presentant une ligne de resultat d'une selection |
| 357 | 357 | */ |
| 358 | -function sql_fetch_all($res, $serveur='', $option=true){ |
|
| 358 | +function sql_fetch_all($res, $serveur = '', $option = true) { |
|
| 359 | 359 | $rows = array(); |
| 360 | 360 | if (!$res) return $rows; |
| 361 | - $f = sql_serveur('fetch', $serveur, $option==='continue' OR $option===false); |
|
| 361 | + $f = sql_serveur('fetch', $serveur, $option === 'continue' OR $option === false); |
|
| 362 | 362 | if (!is_string($f) OR !$f) return array(); |
| 363 | - while ($r = $f($res, NULL, $serveur, $option!==false)) |
|
| 363 | + while ($r = $f($res, NULL, $serveur, $option !== false)) |
|
| 364 | 364 | $rows[] = $r; |
| 365 | 365 | sql_free($res, $serveur); |
| 366 | 366 | return $rows; |
@@ -390,11 +390,11 @@ discard block |
||
| 390 | 390 | * @return bool |
| 391 | 391 | * Operation effectuee (true), sinon false. |
| 392 | 392 | **/ |
| 393 | -function sql_seek($res, $row_number, $serveur='', $option=true) { |
|
| 394 | - $f = sql_serveur('seek', $serveur, $option==='continue' OR $option===false); |
|
| 393 | +function sql_seek($res, $row_number, $serveur = '', $option = true) { |
|
| 394 | + $f = sql_serveur('seek', $serveur, $option === 'continue' OR $option === false); |
|
| 395 | 395 | if (!is_string($f) OR !$f) return false; |
| 396 | - $r = $f($res, $row_number, $serveur, $option!==false); |
|
| 397 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 396 | + $r = $f($res, $row_number, $serveur, $option !== false); |
|
| 397 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 398 | 398 | return $r; |
| 399 | 399 | } |
| 400 | 400 | |
@@ -419,11 +419,11 @@ discard block |
||
| 419 | 419 | * Tableau contenant chaque nom de base de donnees. |
| 420 | 420 | * False en cas d'erreur. |
| 421 | 421 | **/ |
| 422 | -function sql_listdbs($serveur='', $option=true) { |
|
| 423 | - $f = sql_serveur('listdbs', $serveur, $option==='continue' OR $option===false); |
|
| 422 | +function sql_listdbs($serveur = '', $option = true) { |
|
| 423 | + $f = sql_serveur('listdbs', $serveur, $option === 'continue' OR $option === false); |
|
| 424 | 424 | if (!is_string($f) OR !$f) return false; |
| 425 | 425 | $r = $f($serveur); |
| 426 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 426 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 427 | 427 | return $r; |
| 428 | 428 | } |
| 429 | 429 | |
@@ -445,29 +445,29 @@ discard block |
||
| 445 | 445 | * True ou nom de la base en cas de success. |
| 446 | 446 | * False en cas d'erreur. |
| 447 | 447 | **/ |
| 448 | -function sql_selectdb($nom, $serveur='', $option=true) |
|
| 448 | +function sql_selectdb($nom, $serveur = '', $option = true) |
|
| 449 | 449 | { |
| 450 | - $f = sql_serveur('selectdb', $serveur, $option==='continue' OR $option===false); |
|
| 450 | + $f = sql_serveur('selectdb', $serveur, $option === 'continue' OR $option === false); |
|
| 451 | 451 | if (!is_string($f) OR !$f) return false; |
| 452 | - $r = $f($nom, $serveur, $option!==false); |
|
| 453 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 452 | + $r = $f($nom, $serveur, $option !== false); |
|
| 453 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 454 | 454 | return $r; |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | // http://doc.spip.org/@sql_count |
| 458 | -function sql_count($res, $serveur='', $option=true) |
|
| 458 | +function sql_count($res, $serveur = '', $option = true) |
|
| 459 | 459 | { |
| 460 | - $f = sql_serveur('count', $serveur, $option==='continue' OR $option===false); |
|
| 460 | + $f = sql_serveur('count', $serveur, $option === 'continue' OR $option === false); |
|
| 461 | 461 | if (!is_string($f) OR !$f) return false; |
| 462 | - $r = $f($res, $serveur, $option!==false); |
|
| 463 | - if ($r===false) spip_sql_erreur($serveur); |
|
| 462 | + $r = $f($res, $serveur, $option !== false); |
|
| 463 | + if ($r === false) spip_sql_erreur($serveur); |
|
| 464 | 464 | return $r; |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | // http://doc.spip.org/@sql_free |
| 468 | -function sql_free($res, $serveur='', $option=true) |
|
| 468 | +function sql_free($res, $serveur = '', $option = true) |
|
| 469 | 469 | { |
| 470 | - $f = sql_serveur('free', $serveur, $option==='continue' OR $option===false); |
|
| 470 | + $f = sql_serveur('free', $serveur, $option === 'continue' OR $option === false); |
|
| 471 | 471 | if (!is_string($f) OR !$f) return false; |
| 472 | 472 | return $f($res); |
| 473 | 473 | } |
@@ -477,41 +477,41 @@ discard block |
||
| 477 | 477 | // Elle est fournie pour permettre l'actualisation de vieux codes |
| 478 | 478 | // par un Sed brutal qui peut donner des resultats provisoirement acceptables |
| 479 | 479 | // http://doc.spip.org/@sql_insert |
| 480 | -function sql_insert($table, $noms, $valeurs, $desc=array(), $serveur='', $option=true) |
|
| 480 | +function sql_insert($table, $noms, $valeurs, $desc = array(), $serveur = '', $option = true) |
|
| 481 | 481 | { |
| 482 | - $f = sql_serveur('insert', $serveur, $option==='continue' OR $option===false); |
|
| 482 | + $f = sql_serveur('insert', $serveur, $option === 'continue' OR $option === false); |
|
| 483 | 483 | if (!is_string($f) OR !$f) return false; |
| 484 | - $r = $f($table, $noms, $valeurs, $desc, $serveur, $option!==false); |
|
| 484 | + $r = $f($table, $noms, $valeurs, $desc, $serveur, $option !== false); |
|
| 485 | 485 | if ($r === false) spip_sql_erreur($serveur); |
| 486 | 486 | return $r; |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | // http://doc.spip.org/@sql_insertq |
| 490 | -function sql_insertq($table, $couples=array(), $desc=array(), $serveur='', $option=true) |
|
| 490 | +function sql_insertq($table, $couples = array(), $desc = array(), $serveur = '', $option = true) |
|
| 491 | 491 | { |
| 492 | - $f = sql_serveur('insertq', $serveur, $option==='continue' OR $option===false); |
|
| 492 | + $f = sql_serveur('insertq', $serveur, $option === 'continue' OR $option === false); |
|
| 493 | 493 | if (!is_string($f) OR !$f) return false; |
| 494 | - $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 494 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 495 | 495 | if ($r === false) spip_sql_erreur($serveur); |
| 496 | 496 | return $r; |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | // http://doc.spip.org/@sql_insertq_multi |
| 500 | -function sql_insertq_multi($table, $couples=array(), $desc=array(), $serveur='', $option=true) |
|
| 500 | +function sql_insertq_multi($table, $couples = array(), $desc = array(), $serveur = '', $option = true) |
|
| 501 | 501 | { |
| 502 | - $f = sql_serveur('insertq_multi', $serveur, $option==='continue' OR $option===false); |
|
| 502 | + $f = sql_serveur('insertq_multi', $serveur, $option === 'continue' OR $option === false); |
|
| 503 | 503 | if (!is_string($f) OR !$f) return false; |
| 504 | - $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 504 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 505 | 505 | if ($r === false) spip_sql_erreur($serveur); |
| 506 | 506 | return $r; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | // http://doc.spip.org/@sql_update |
| 510 | -function sql_update($table, $exp, $where='', $desc=array(), $serveur='', $option=true) |
|
| 510 | +function sql_update($table, $exp, $where = '', $desc = array(), $serveur = '', $option = true) |
|
| 511 | 511 | { |
| 512 | - $f = sql_serveur('update', $serveur, $option==='continue' OR $option===false); |
|
| 512 | + $f = sql_serveur('update', $serveur, $option === 'continue' OR $option === false); |
|
| 513 | 513 | if (!is_string($f) OR !$f) return false; |
| 514 | - $r = $f($table, $exp, $where, $desc, $serveur, $option!==false); |
|
| 514 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 515 | 515 | if ($r === false) spip_sql_erreur($serveur); |
| 516 | 516 | return $r; |
| 517 | 517 | } |
@@ -520,63 +520,63 @@ discard block |
||
| 520 | 520 | // Cette fonction est donc plus utile que la precedente,d'autant qu'elle |
| 521 | 521 | // permet de gerer les differences de representation des constantes. |
| 522 | 522 | // http://doc.spip.org/@sql_updateq |
| 523 | -function sql_updateq($table, $exp, $where='', $desc=array(), $serveur='', $option=true) |
|
| 523 | +function sql_updateq($table, $exp, $where = '', $desc = array(), $serveur = '', $option = true) |
|
| 524 | 524 | { |
| 525 | - $f = sql_serveur('updateq', $serveur, $option==='continue' OR $option===false); |
|
| 525 | + $f = sql_serveur('updateq', $serveur, $option === 'continue' OR $option === false); |
|
| 526 | 526 | if (!is_string($f) OR !$f) return false; |
| 527 | - $r = $f($table, $exp, $where, $desc, $serveur, $option!==false); |
|
| 527 | + $r = $f($table, $exp, $where, $desc, $serveur, $option !== false); |
|
| 528 | 528 | if ($r === false) spip_sql_erreur($serveur); |
| 529 | 529 | return $r; |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | // http://doc.spip.org/@sql_delete |
| 533 | -function sql_delete($table, $where='', $serveur='', $option=true) |
|
| 533 | +function sql_delete($table, $where = '', $serveur = '', $option = true) |
|
| 534 | 534 | { |
| 535 | - $f = sql_serveur('delete', $serveur, $option==='continue' OR $option===false); |
|
| 535 | + $f = sql_serveur('delete', $serveur, $option === 'continue' OR $option === false); |
|
| 536 | 536 | if (!is_string($f) OR !$f) return false; |
| 537 | - $r = $f($table, $where, $serveur, $option!==false); |
|
| 537 | + $r = $f($table, $where, $serveur, $option !== false); |
|
| 538 | 538 | if ($r === false) spip_sql_erreur($serveur); |
| 539 | 539 | return $r; |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | // http://doc.spip.org/@sql_replace |
| 543 | -function sql_replace($table, $couples, $desc=array(), $serveur='', $option=true) |
|
| 543 | +function sql_replace($table, $couples, $desc = array(), $serveur = '', $option = true) |
|
| 544 | 544 | { |
| 545 | - $f = sql_serveur('replace', $serveur, $option==='continue' OR $option===false); |
|
| 545 | + $f = sql_serveur('replace', $serveur, $option === 'continue' OR $option === false); |
|
| 546 | 546 | if (!is_string($f) OR !$f) return false; |
| 547 | - $r = $f($table, $couples, $desc, $serveur, $option!==false); |
|
| 547 | + $r = $f($table, $couples, $desc, $serveur, $option !== false); |
|
| 548 | 548 | if ($r === false) spip_sql_erreur($serveur); |
| 549 | 549 | return $r; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | |
| 553 | 553 | // http://doc.spip.org/@sql_replace_multi |
| 554 | -function sql_replace_multi($table, $tab_couples, $desc=array(), $serveur='', $option=true) |
|
| 554 | +function sql_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $option = true) |
|
| 555 | 555 | { |
| 556 | - $f = sql_serveur('replace_multi', $serveur, $option==='continue' OR $option===false); |
|
| 556 | + $f = sql_serveur('replace_multi', $serveur, $option === 'continue' OR $option === false); |
|
| 557 | 557 | if (!is_string($f) OR !$f) return false; |
| 558 | - $r = $f($table, $tab_couples, $desc, $serveur, $option!==false); |
|
| 558 | + $r = $f($table, $tab_couples, $desc, $serveur, $option !== false); |
|
| 559 | 559 | if ($r === false) spip_sql_erreur($serveur); |
| 560 | 560 | return $r; |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | // http://doc.spip.org/@sql_drop_table |
| 564 | -function sql_drop_table($table, $exist='', $serveur='', $option=true) |
|
| 564 | +function sql_drop_table($table, $exist = '', $serveur = '', $option = true) |
|
| 565 | 565 | { |
| 566 | - $f = sql_serveur('drop_table', $serveur, $option==='continue' OR $option===false); |
|
| 566 | + $f = sql_serveur('drop_table', $serveur, $option === 'continue' OR $option === false); |
|
| 567 | 567 | if (!is_string($f) OR !$f) return false; |
| 568 | - $r = $f($table, $exist, $serveur, $option!==false); |
|
| 568 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 569 | 569 | if ($r === false) spip_sql_erreur($serveur); |
| 570 | 570 | return $r; |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | // supprimer une vue sql |
| 574 | 574 | // http://doc.spip.org/@sql_drop_view |
| 575 | -function sql_drop_view($table, $exist='', $serveur='', $option=true) |
|
| 575 | +function sql_drop_view($table, $exist = '', $serveur = '', $option = true) |
|
| 576 | 576 | { |
| 577 | - $f = sql_serveur('drop_view', $serveur, $option==='continue' OR $option===false); |
|
| 577 | + $f = sql_serveur('drop_view', $serveur, $option === 'continue' OR $option === false); |
|
| 578 | 578 | if (!is_string($f) OR !$f) return false; |
| 579 | - $r = $f($table, $exist, $serveur, $option!==false); |
|
| 579 | + $r = $f($table, $exist, $serveur, $option !== false); |
|
| 580 | 580 | if ($r === false) spip_sql_erreur($serveur); |
| 581 | 581 | return $r; |
| 582 | 582 | } |
@@ -599,18 +599,18 @@ discard block |
||
| 599 | 599 | * @return ressource |
| 600 | 600 | * Ressource à utiliser avec sql_fetch() |
| 601 | 601 | **/ |
| 602 | -function sql_showbase($spip=NULL, $serveur='', $option=true) |
|
| 602 | +function sql_showbase($spip = NULL, $serveur = '', $option = true) |
|
| 603 | 603 | { |
| 604 | - $f = sql_serveur('showbase', $serveur, $option==='continue' OR $option===false); |
|
| 604 | + $f = sql_serveur('showbase', $serveur, $option === 'continue' OR $option === false); |
|
| 605 | 605 | if (!is_string($f) OR !$f) return false; |
| 606 | 606 | |
| 607 | 607 | // la globale n'est remplie qu'apres l'appel de sql_serveur. |
| 608 | - if ($spip == NULL){ |
|
| 608 | + if ($spip == NULL) { |
|
| 609 | 609 | $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 610 | - $spip = $connexion['prefixe'] . '\_%'; |
|
| 610 | + $spip = $connexion['prefixe'].'\_%'; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - return $f($spip, $serveur, $option!==false); |
|
| 613 | + return $f($spip, $serveur, $option !== false); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -632,28 +632,28 @@ discard block |
||
| 632 | 632 | * @return array |
| 633 | 633 | * Liste des tables SQL |
| 634 | 634 | **/ |
| 635 | -function sql_alltable($spip=NULL, $serveur='', $option=true) |
|
| 635 | +function sql_alltable($spip = NULL, $serveur = '', $option = true) |
|
| 636 | 636 | { |
| 637 | 637 | $q = sql_showbase($spip, $serveur, $option); |
| 638 | 638 | $r = array(); |
| 639 | - if ($q) while ($t = sql_fetch($q, $serveur)) { $r[] = array_shift($t);} |
|
| 639 | + if ($q) while ($t = sql_fetch($q, $serveur)) { $r[] = array_shift($t); } |
|
| 640 | 640 | return $r; |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | 643 | // http://doc.spip.org/@sql_showtable |
| 644 | -function sql_showtable($table, $table_spip = false, $serveur='', $option=true) |
|
| 644 | +function sql_showtable($table, $table_spip = false, $serveur = '', $option = true) |
|
| 645 | 645 | { |
| 646 | - $f = sql_serveur('showtable', $serveur, $option==='continue' OR $option===false); |
|
| 646 | + $f = sql_serveur('showtable', $serveur, $option === 'continue' OR $option === false); |
|
| 647 | 647 | if (!is_string($f) OR !$f) return false; |
| 648 | 648 | |
| 649 | 649 | // la globale n'est remplie qu'apres l'appel de sql_serveur. |
| 650 | - if ($table_spip){ |
|
| 650 | + if ($table_spip) { |
|
| 651 | 651 | $connexion = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 652 | 652 | $prefixe = $connexion['prefixe']; |
| 653 | 653 | $vraie_table = preg_replace('/^spip/', $prefixe, $table); |
| 654 | 654 | } else $vraie_table = $table; |
| 655 | 655 | |
| 656 | - $f = $f($vraie_table, $serveur, $option!==false); |
|
| 656 | + $f = $f($vraie_table, $serveur, $option !== false); |
|
| 657 | 657 | if (!$f) return array(); |
| 658 | 658 | if (isset($GLOBALS['tables_principales'][$table]['join'])) |
| 659 | 659 | $f['join'] = $GLOBALS['tables_principales'][$table]['join']; |
@@ -663,19 +663,19 @@ discard block |
||
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | // http://doc.spip.org/@sql_create |
| 666 | -function sql_create($nom, $champs, $cles=array(), $autoinc=false, $temporary=false, $serveur='', $option=true) { |
|
| 667 | - $f = sql_serveur('create', $serveur, $option==='continue' OR $option===false); |
|
| 666 | +function sql_create($nom, $champs, $cles = array(), $autoinc = false, $temporary = false, $serveur = '', $option = true) { |
|
| 667 | + $f = sql_serveur('create', $serveur, $option === 'continue' OR $option === false); |
|
| 668 | 668 | if (!is_string($f) OR !$f) return false; |
| 669 | - $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option!==false); |
|
| 669 | + $r = $f($nom, $champs, $cles, $autoinc, $temporary, $serveur, $option !== false); |
|
| 670 | 670 | if ($r === false) spip_sql_erreur($serveur); |
| 671 | 671 | return $r; |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | -function sql_create_base($nom, $serveur='', $option=true) |
|
| 674 | +function sql_create_base($nom, $serveur = '', $option = true) |
|
| 675 | 675 | { |
| 676 | - $f = sql_serveur('create_base', $serveur, $option==='continue' OR $option===false); |
|
| 676 | + $f = sql_serveur('create_base', $serveur, $option === 'continue' OR $option === false); |
|
| 677 | 677 | if (!is_string($f) OR !$f) return false; |
| 678 | - $r = $f($nom, $serveur, $option!==false); |
|
| 678 | + $r = $f($nom, $serveur, $option !== false); |
|
| 679 | 679 | if ($r === false) spip_sql_erreur($serveur); |
| 680 | 680 | return $r; |
| 681 | 681 | } |
@@ -685,18 +685,18 @@ discard block |
||
| 685 | 685 | // select_query : une requete select, idealement cree avec $req = sql_select() |
| 686 | 686 | // (en mettant $option du sql_select a false pour recuperer la requete) |
| 687 | 687 | // http://doc.spip.org/@sql_create_view |
| 688 | -function sql_create_view($nom, $select_query, $serveur='', $option=true) { |
|
| 689 | - $f = sql_serveur('create_view', $serveur, $option==='continue' OR $option===false); |
|
| 688 | +function sql_create_view($nom, $select_query, $serveur = '', $option = true) { |
|
| 689 | + $f = sql_serveur('create_view', $serveur, $option === 'continue' OR $option === false); |
|
| 690 | 690 | if (!is_string($f) OR !$f) return false; |
| 691 | - $r = $f($nom, $select_query, $serveur, $option!==false); |
|
| 691 | + $r = $f($nom, $select_query, $serveur, $option !== false); |
|
| 692 | 692 | if ($r === false) spip_sql_erreur($serveur); |
| 693 | 693 | return $r; |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | // http://doc.spip.org/@sql_multi |
| 697 | -function sql_multi($sel, $lang, $serveur='', $option=true) |
|
| 697 | +function sql_multi($sel, $lang, $serveur = '', $option = true) |
|
| 698 | 698 | { |
| 699 | - $f = sql_serveur('multi', $serveur, $option==='continue' OR $option===false); |
|
| 699 | + $f = sql_serveur('multi', $serveur, $option === 'continue' OR $option === false); |
|
| 700 | 700 | if (!is_string($f) OR !$f) return false; |
| 701 | 701 | return $f($sel, $lang); |
| 702 | 702 | } |
@@ -712,7 +712,7 @@ discard block |
||
| 712 | 712 | * Description de l'erreur |
| 713 | 713 | * False si le serveur est indisponible |
| 714 | 714 | */ |
| 715 | -function sql_error($serveur='') { |
|
| 715 | +function sql_error($serveur = '') { |
|
| 716 | 716 | $f = sql_serveur('error', $serveur, 'continue'); |
| 717 | 717 | if (!is_string($f) OR !$f) return false; |
| 718 | 718 | return $f('query inconnue', $serveur); |
@@ -728,35 +728,35 @@ discard block |
||
| 728 | 728 | * Numéro de l'erreur |
| 729 | 729 | * False si le serveur est indisponible |
| 730 | 730 | */ |
| 731 | -function sql_errno($serveur='') { |
|
| 731 | +function sql_errno($serveur = '') { |
|
| 732 | 732 | $f = sql_serveur('errno', $serveur, 'continue'); |
| 733 | 733 | if (!is_string($f) OR !$f) return false; |
| 734 | 734 | return $f($serveur); |
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | // http://doc.spip.org/@sql_explain |
| 738 | -function sql_explain($q, $serveur='', $option=true) { |
|
| 739 | - $f = sql_serveur('explain', $serveur, 'continue'); |
|
| 738 | +function sql_explain($q, $serveur = '', $option = true) { |
|
| 739 | + $f = sql_serveur('explain', $serveur, 'continue'); |
|
| 740 | 740 | if (!is_string($f) OR !$f) return false; |
| 741 | - $r = $f($q, $serveur, $option!==false); |
|
| 741 | + $r = $f($q, $serveur, $option !== false); |
|
| 742 | 742 | if ($r === false) spip_sql_erreur($serveur); |
| 743 | 743 | return $r; |
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | // http://doc.spip.org/@sql_optimize |
| 747 | -function sql_optimize($table, $serveur='', $option=true) { |
|
| 748 | - $f = sql_serveur('optimize', $serveur, $option==='continue' OR $option===false); |
|
| 747 | +function sql_optimize($table, $serveur = '', $option = true) { |
|
| 748 | + $f = sql_serveur('optimize', $serveur, $option === 'continue' OR $option === false); |
|
| 749 | 749 | if (!is_string($f) OR !$f) return false; |
| 750 | - $r = $f($table, $serveur, $option!==false); |
|
| 750 | + $r = $f($table, $serveur, $option !== false); |
|
| 751 | 751 | if ($r === false) spip_sql_erreur($serveur); |
| 752 | 752 | return $r; |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | // http://doc.spip.org/@sql_repair |
| 756 | -function sql_repair($table, $serveur='', $option=true) { |
|
| 757 | - $f = sql_serveur('repair', $serveur, $option==='continue' OR $option===false); |
|
| 756 | +function sql_repair($table, $serveur = '', $option = true) { |
|
| 757 | + $f = sql_serveur('repair', $serveur, $option === 'continue' OR $option === false); |
|
| 758 | 758 | if (!is_string($f) OR !$f) return false; |
| 759 | - $r = $f($table, $serveur, $option!==false); |
|
| 759 | + $r = $f($table, $serveur, $option !== false); |
|
| 760 | 760 | if ($r === false) spip_sql_erreur($serveur); |
| 761 | 761 | return $r; |
| 762 | 762 | } |
@@ -765,10 +765,10 @@ discard block |
||
| 765 | 765 | // A n'utiliser qu'en derniere extremite |
| 766 | 766 | |
| 767 | 767 | // http://doc.spip.org/@sql_query |
| 768 | -function sql_query($ins, $serveur='', $option=true) { |
|
| 769 | - $f = sql_serveur('query', $serveur, $option==='continue' OR $option===false); |
|
| 768 | +function sql_query($ins, $serveur = '', $option = true) { |
|
| 769 | + $f = sql_serveur('query', $serveur, $option === 'continue' OR $option === false); |
|
| 770 | 770 | if (!is_string($f) OR !$f) return false; |
| 771 | - $r = $f($ins, $serveur, $option!==false); |
|
| 771 | + $r = $f($ins, $serveur, $option !== false); |
|
| 772 | 772 | if ($r === false) spip_sql_erreur($serveur); |
| 773 | 773 | return $r; |
| 774 | 774 | } |
@@ -820,9 +820,9 @@ discard block |
||
| 820 | 820 | **/ |
| 821 | 821 | function sql_fetsel($select = array(), $from = array(), $where = array(), |
| 822 | 822 | $groupby = array(), $orderby = array(), $limit = '', |
| 823 | - $having = array(), $serveur='', $option=true) { |
|
| 824 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 825 | - if ($option===false) return $q; |
|
| 823 | + $having = array(), $serveur = '', $option = true) { |
|
| 824 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 825 | + if ($option === false) return $q; |
|
| 826 | 826 | if (!$q) return array(); |
| 827 | 827 | $r = sql_fetch($q, $serveur, $option); |
| 828 | 828 | sql_free($q, $serveur, $option); |
@@ -884,9 +884,9 @@ discard block |
||
| 884 | 884 | **/ |
| 885 | 885 | function sql_allfetsel($select = array(), $from = array(), $where = array(), |
| 886 | 886 | $groupby = array(), $orderby = array(), $limit = '', |
| 887 | - $having = array(), $serveur='', $option=true) { |
|
| 888 | - $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 889 | - if ($option===false) return $q; |
|
| 887 | + $having = array(), $serveur = '', $option = true) { |
|
| 888 | + $q = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 889 | + if ($option === false) return $q; |
|
| 890 | 890 | return sql_fetch_all($q, $serveur, $option); |
| 891 | 891 | } |
| 892 | 892 | |
@@ -932,12 +932,12 @@ discard block |
||
| 932 | 932 | * |
| 933 | 933 | **/ |
| 934 | 934 | function sql_getfetsel($select, $from = array(), $where = array(), $groupby = array(), |
| 935 | - $orderby = array(), $limit = '', $having = array(), $serveur='', $option=true) { |
|
| 935 | + $orderby = array(), $limit = '', $having = array(), $serveur = '', $option = true) { |
|
| 936 | 936 | if (preg_match('/\s+as\s+(\w+)$/i', $select, $c)) $id = $c[1]; |
| 937 | 937 | elseif (!preg_match('/\W/', $select)) $id = $select; |
| 938 | - else {$id = 'n'; $select .= ' AS n';} |
|
| 939 | - $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 940 | - if ($option===false) return $r; |
|
| 938 | + else {$id = 'n'; $select .= ' AS n'; } |
|
| 939 | + $r = sql_fetsel($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur, $option); |
|
| 940 | + if ($option === false) return $r; |
|
| 941 | 941 | if (!$r) return NULL; |
| 942 | 942 | return $r[$id]; |
| 943 | 943 | } |
@@ -956,8 +956,8 @@ discard block |
||
| 956 | 956 | * @return string |
| 957 | 957 | * Numero de version du serveur SQL |
| 958 | 958 | **/ |
| 959 | -function sql_version($serveur='', $option=true) { |
|
| 960 | - $row = sql_fetsel("version() AS n", '','','','','','',$serveur); |
|
| 959 | +function sql_version($serveur = '', $option = true) { |
|
| 960 | + $row = sql_fetsel("version() AS n", '', '', '', '', '', '', $serveur); |
|
| 961 | 961 | return ($row['n']); |
| 962 | 962 | } |
| 963 | 963 | |
@@ -993,10 +993,10 @@ discard block |
||
| 993 | 993 | * @return bool |
| 994 | 994 | * Le serveur SQL prefere t'il des transactions pour les insertions multiples ? |
| 995 | 995 | **/ |
| 996 | -function sql_preferer_transaction($serveur='', $option=true) { |
|
| 997 | - $f = sql_serveur('preferer_transaction', $serveur, 'continue'); |
|
| 996 | +function sql_preferer_transaction($serveur = '', $option = true) { |
|
| 997 | + $f = sql_serveur('preferer_transaction', $serveur, 'continue'); |
|
| 998 | 998 | if (!is_string($f) OR !$f) return false; |
| 999 | - $r = $f($serveur, $option!==false); |
|
| 999 | + $r = $f($serveur, $option !== false); |
|
| 1000 | 1000 | if ($r === false) spip_sql_erreur($serveur); |
| 1001 | 1001 | return $r; |
| 1002 | 1002 | }; |
@@ -1019,10 +1019,10 @@ discard block |
||
| 1019 | 1019 | * true si la transaction est demarree |
| 1020 | 1020 | * false en cas d'erreur |
| 1021 | 1021 | **/ |
| 1022 | -function sql_demarrer_transaction($serveur='', $option=true) { |
|
| 1023 | - $f = sql_serveur('demarrer_transaction', $serveur, 'continue'); |
|
| 1022 | +function sql_demarrer_transaction($serveur = '', $option = true) { |
|
| 1023 | + $f = sql_serveur('demarrer_transaction', $serveur, 'continue'); |
|
| 1024 | 1024 | if (!is_string($f) OR !$f) return false; |
| 1025 | - $r = $f($serveur, $option!==false); |
|
| 1025 | + $r = $f($serveur, $option !== false); |
|
| 1026 | 1026 | if ($r === false) spip_sql_erreur($serveur); |
| 1027 | 1027 | return $r; |
| 1028 | 1028 | }; |
@@ -1045,10 +1045,10 @@ discard block |
||
| 1045 | 1045 | * true si la transaction est demarree |
| 1046 | 1046 | * false en cas d'erreur |
| 1047 | 1047 | **/ |
| 1048 | -function sql_terminer_transaction($serveur='', $option=true) { |
|
| 1049 | - $f = sql_serveur('terminer_transaction', $serveur, 'continue'); |
|
| 1048 | +function sql_terminer_transaction($serveur = '', $option = true) { |
|
| 1049 | + $f = sql_serveur('terminer_transaction', $serveur, 'continue'); |
|
| 1050 | 1050 | if (!is_string($f) OR !$f) return false; |
| 1051 | - $r = $f($serveur, $option!==false); |
|
| 1051 | + $r = $f($serveur, $option !== false); |
|
| 1052 | 1052 | if ($r === false) spip_sql_erreur($serveur); |
| 1053 | 1053 | return $r; |
| 1054 | 1054 | }; |
@@ -1073,9 +1073,9 @@ discard block |
||
| 1073 | 1073 | * @return string |
| 1074 | 1074 | * Retourne la valeur hexadecimale attendue par le serveur SQL |
| 1075 | 1075 | **/ |
| 1076 | -function sql_hex($val, $serveur='', $option=true) |
|
| 1076 | +function sql_hex($val, $serveur = '', $option = true) |
|
| 1077 | 1077 | { |
| 1078 | - $f = sql_serveur('hex', $serveur, $option==='continue' OR $option===false); |
|
| 1078 | + $f = sql_serveur('hex', $serveur, $option === 'continue' OR $option === false); |
|
| 1079 | 1079 | if (!is_string($f) OR !$f) return false; |
| 1080 | 1080 | return $f($val); |
| 1081 | 1081 | } |
@@ -1100,14 +1100,14 @@ discard block |
||
| 1100 | 1100 | * @return string |
| 1101 | 1101 | * La chaine echappee |
| 1102 | 1102 | **/ |
| 1103 | -function sql_quote($val, $serveur='', $type='') |
|
| 1103 | +function sql_quote($val, $serveur = '', $type = '') |
|
| 1104 | 1104 | { |
| 1105 | 1105 | $f = sql_serveur('quote', $serveur, true); |
| 1106 | 1106 | if (!is_string($f) OR !$f) $f = '_q'; |
| 1107 | 1107 | return $f($val, $type); |
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | -function sql_date_proche($champ, $interval, $unite, $serveur='', $option=true) |
|
| 1110 | +function sql_date_proche($champ, $interval, $unite, $serveur = '', $option = true) |
|
| 1111 | 1111 | { |
| 1112 | 1112 | $f = sql_serveur('date_proche', $serveur, true); |
| 1113 | 1113 | if (!is_string($f) OR !$f) return false; |
@@ -1142,17 +1142,17 @@ discard block |
||
| 1142 | 1142 | * @return string |
| 1143 | 1143 | * Expression de requête SQL |
| 1144 | 1144 | **/ |
| 1145 | -function sql_in($val, $valeurs, $not='', $serveur='', $option=true) { |
|
| 1145 | +function sql_in($val, $valeurs, $not = '', $serveur = '', $option = true) { |
|
| 1146 | 1146 | if (is_array($valeurs)) { |
| 1147 | 1147 | $f = sql_serveur('quote', $serveur, true); |
| 1148 | 1148 | if (!is_string($f) OR !$f) return false; |
| 1149 | 1149 | $valeurs = join(',', array_map($f, array_unique($valeurs))); |
| 1150 | - } elseif (isset($valeurs[0]) AND $valeurs[0]===',') $valeurs = substr($valeurs,1); |
|
| 1150 | + } elseif (isset($valeurs[0]) AND $valeurs[0] === ',') $valeurs = substr($valeurs, 1); |
|
| 1151 | 1151 | if (!strlen(trim($valeurs))) return ($not ? "0=0" : '0=1'); |
| 1152 | 1152 | |
| 1153 | - $f = sql_serveur('in', $serveur, $option==='continue' OR $option===false); |
|
| 1153 | + $f = sql_serveur('in', $serveur, $option === 'continue' OR $option === false); |
|
| 1154 | 1154 | if (!is_string($f) OR !$f) return false; |
| 1155 | - return $f($val, $valeurs, $not, $serveur, $option!==false); |
|
| 1155 | + return $f($val, $valeurs, $not, $serveur, $option !== false); |
|
| 1156 | 1156 | } |
| 1157 | 1157 | |
| 1158 | 1158 | // Penser a dire dans la description du serveur |
@@ -1160,11 +1160,11 @@ discard block |
||
| 1160 | 1160 | |
| 1161 | 1161 | // http://doc.spip.org/@sql_in_select |
| 1162 | 1162 | function sql_in_select($in, $select, $from = array(), $where = array(), |
| 1163 | - $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur='') |
|
| 1163 | + $groupby = array(), $orderby = array(), $limit = '', $having = array(), $serveur = '') |
|
| 1164 | 1164 | { |
| 1165 | 1165 | $liste = array(); |
| 1166 | 1166 | $res = sql_select($select, $from, $where, $groupby, $orderby, $limit, $having, $serveur); |
| 1167 | - while ($r = sql_fetch($res)) {$liste[] = array_shift($r);} |
|
| 1167 | + while ($r = sql_fetch($res)) {$liste[] = array_shift($r); } |
|
| 1168 | 1168 | sql_free($res); |
| 1169 | 1169 | return sql_in($in, $liste); |
| 1170 | 1170 | } |
@@ -1196,33 +1196,33 @@ discard block |
||
| 1196 | 1196 | * @return int |
| 1197 | 1197 | * Position apres le saut. |
| 1198 | 1198 | */ |
| 1199 | -function sql_skip($res, $pos, $saut, $count, $serveur='', $option=true){ |
|
| 1199 | +function sql_skip($res, $pos, $saut, $count, $serveur = '', $option = true) { |
|
| 1200 | 1200 | // pas de saut en arriere qu'on ne sait pas faire sans sql_seek |
| 1201 | - if (($saut=intval($saut))<=0) return $pos; |
|
| 1201 | + if (($saut = intval($saut)) <= 0) return $pos; |
|
| 1202 | 1202 | |
| 1203 | 1203 | $seek = $pos + $saut; |
| 1204 | 1204 | // si le saut fait depasser le maxi, on libere la resource |
| 1205 | 1205 | // et on sort |
| 1206 | - if ($seek>=$count) {sql_free($res, $serveur, $option); return $count;} |
|
| 1206 | + if ($seek >= $count) {sql_free($res, $serveur, $option); return $count; } |
|
| 1207 | 1207 | |
| 1208 | 1208 | if (sql_seek($res, $seek)) |
| 1209 | 1209 | $pos = $seek; |
| 1210 | 1210 | else |
| 1211 | - while ($pos<$seek AND sql_fetch($res, $serveur, $option)) |
|
| 1211 | + while ($pos < $seek AND sql_fetch($res, $serveur, $option)) |
|
| 1212 | 1212 | $pos++; |
| 1213 | 1213 | return $pos; |
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | // http://doc.spip.org/@sql_test_int |
| 1217 | -function sql_test_int($type, $serveur='', $option=true) |
|
| 1217 | +function sql_test_int($type, $serveur = '', $option = true) |
|
| 1218 | 1218 | { |
| 1219 | - return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i',trim($type)); |
|
| 1219 | + return preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT)/i', trim($type)); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | // http://doc.spip.org/@sql_test_date |
| 1223 | -function sql_test_date($type, $serveur='', $option=true) |
|
| 1223 | +function sql_test_date($type, $serveur = '', $option = true) |
|
| 1224 | 1224 | { |
| 1225 | - return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i',trim($type)); |
|
| 1225 | + return preg_match('/^(DATE|DATETIME|TIMESTAMP|TIME)/i', trim($type)); |
|
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | /** |
@@ -1244,16 +1244,16 @@ discard block |
||
| 1244 | 1244 | * @return string |
| 1245 | 1245 | * La date formatee |
| 1246 | 1246 | */ |
| 1247 | -function sql_format_date($annee=0, $mois=0, $jour=0, $h=0, $m=0, $s=0, $serveur=''){ |
|
| 1248 | - $annee = sprintf("%04s",$annee); |
|
| 1249 | - $mois = sprintf("%02s",$mois); |
|
| 1247 | +function sql_format_date($annee = 0, $mois = 0, $jour = 0, $h = 0, $m = 0, $s = 0, $serveur = '') { |
|
| 1248 | + $annee = sprintf("%04s", $annee); |
|
| 1249 | + $mois = sprintf("%02s", $mois); |
|
| 1250 | 1250 | |
| 1251 | 1251 | if ($annee == "0000") $mois = 0; |
| 1252 | 1252 | if ($mois == "00") $jour = 0; |
| 1253 | 1253 | |
| 1254 | - return sprintf("%04u",$annee) . '-' . sprintf("%02u",$mois) . '-' |
|
| 1255 | - . sprintf("%02u",$jour) . ' ' . sprintf("%02u",$h) . ':' |
|
| 1256 | - . sprintf("%02u",$m) . ':' . sprintf("%02u",$s); |
|
| 1254 | + return sprintf("%04u", $annee).'-'.sprintf("%02u", $mois).'-' |
|
| 1255 | + . sprintf("%02u", $jour).' '.sprintf("%02u", $h).':' |
|
| 1256 | + . sprintf("%02u", $m).':'.sprintf("%02u", $s); |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | |
@@ -1275,7 +1275,7 @@ discard block |
||
| 1275 | 1275 | * @return array|bool |
| 1276 | 1276 | * Description de la table ou false si elle n'est pas trouvee ou declaree. |
| 1277 | 1277 | **/ |
| 1278 | -function description_table($nom, $serveur=''){ |
|
| 1278 | +function description_table($nom, $serveur = '') { |
|
| 1279 | 1279 | |
| 1280 | 1280 | global $tables_principales, $tables_auxiliaires; |
| 1281 | 1281 | static $trouver_table; |
@@ -25,16 +25,16 @@ discard block |
||
| 25 | 25 | * @param array $desc |
| 26 | 26 | * @return bool |
| 27 | 27 | */ |
| 28 | -function base_determine_autoinc($table,$desc=array()){ |
|
| 29 | - if ($t=lister_tables_principales() AND isset($t[$table])) |
|
| 28 | +function base_determine_autoinc($table, $desc = array()) { |
|
| 29 | + if ($t = lister_tables_principales() AND isset($t[$table])) |
|
| 30 | 30 | $autoinc = true; |
| 31 | - elseif ($t=lister_tables_auxiliaires() AND isset($t[$table])) |
|
| 31 | + elseif ($t = lister_tables_auxiliaires() AND isset($t[$table])) |
|
| 32 | 32 | $autoinc = false; |
| 33 | 33 | else { |
| 34 | 34 | // essayer de faire au mieux ! |
| 35 | 35 | $autoinc = (isset($desc['key']['PRIMARY KEY']) |
| 36 | - AND strpos($desc['key']['PRIMARY KEY'],',')===false |
|
| 37 | - AND strpos($desc['field'][$desc['key']['PRIMARY KEY']],'default')===false); |
|
| 36 | + AND strpos($desc['key']['PRIMARY KEY'], ',') === false |
|
| 37 | + AND strpos($desc['field'][$desc['key']['PRIMARY KEY']], 'default') === false); |
|
| 38 | 38 | } |
| 39 | 39 | return $autoinc; |
| 40 | 40 | } |
@@ -54,29 +54,29 @@ discard block |
||
| 54 | 54 | * @param string $serveur |
| 55 | 55 | * @return void |
| 56 | 56 | */ |
| 57 | -function creer_ou_upgrader_table($table,$desc,$autoinc,$upgrade=false,$serveur='') { |
|
| 57 | +function creer_ou_upgrader_table($table, $desc, $autoinc, $upgrade = false, $serveur = '') { |
|
| 58 | 58 | #spip_log("creer_ou_upgrader_table table=$table autoinc=$autoinc upgrade=$upgrade","dbinstall"._LOG_INFO_IMPORTANTE); |
| 59 | - $sql_desc = $upgrade ? sql_showtable($table,true,$serveur) : false; |
|
| 59 | + $sql_desc = $upgrade ? sql_showtable($table, true, $serveur) : false; |
|
| 60 | 60 | #if (!$sql_desc) $sql_desc = false; |
| 61 | 61 | #spip_log("table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
| 62 | 62 | if (!$sql_desc) { |
| 63 | - if ($autoinc==='auto') |
|
| 64 | - $autoinc = base_determine_autoinc($table,$desc); |
|
| 63 | + if ($autoinc === 'auto') |
|
| 64 | + $autoinc = base_determine_autoinc($table, $desc); |
|
| 65 | 65 | #spip_log("sql_create $table autoinc=$autoinc","dbinstall"._LOG_INFO_IMPORTANTE); |
| 66 | 66 | sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
| 67 | 67 | // verifier la bonne installation de la table (php-fpm es-tu la ?) |
| 68 | - $sql_desc = sql_showtable($table,true,$serveur); |
|
| 68 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 69 | 69 | #if (!$sql_desc) $sql_desc = false; |
| 70 | 70 | #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
| 71 | - if (!$sql_desc){ |
|
| 71 | + if (!$sql_desc) { |
|
| 72 | 72 | // on retente avec un sleep ? |
| 73 | 73 | sleep(1); |
| 74 | 74 | sql_create($table, $desc['field'], $desc['key'], $autoinc, false, $serveur); |
| 75 | - $sql_desc = sql_showtable($table,true,$serveur); |
|
| 75 | + $sql_desc = sql_showtable($table, true, $serveur); |
|
| 76 | 76 | #if (!$sql_desc) $sql_desc = false; |
| 77 | 77 | #spip_log("Resultat table=$table sql_desc:$sql_desc","dbinstall"._LOG_INFO_IMPORTANTE); |
| 78 | - if (!$sql_desc){ |
|
| 79 | - spip_log("Echec creation table $table","maj"._LOG_CRITIQUE); |
|
| 78 | + if (!$sql_desc) { |
|
| 79 | + spip_log("Echec creation table $table", "maj"._LOG_CRITIQUE); |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -86,16 +86,16 @@ discard block |
||
| 86 | 86 | // on ne supprime jamais les champs, car c'est dangereux |
| 87 | 87 | // c'est toujours a faire manuellement |
| 88 | 88 | $last = ''; |
| 89 | - foreach($desc['field'] as $field=>$type){ |
|
| 89 | + foreach ($desc['field'] as $field=>$type) { |
|
| 90 | 90 | if (!isset($sql_desc['field'][$field])) |
| 91 | - sql_alter("TABLE $table ADD $field $type".($last?" AFTER $last":""),$serveur); |
|
| 91 | + sql_alter("TABLE $table ADD $field $type".($last ? " AFTER $last" : ""), $serveur); |
|
| 92 | 92 | $last = $field; |
| 93 | 93 | } |
| 94 | - foreach($desc['key'] as $key=>$type){ |
|
| 94 | + foreach ($desc['key'] as $key=>$type) { |
|
| 95 | 95 | // Ne pas oublier les cas des cles non nommees dans la declaration et qui sont retournees |
| 96 | 96 | // par le showtable sous la forme d'un index de tableau "KEY $type" et non "KEY" |
| 97 | 97 | if (!isset($sql_desc['key'][$key]) AND !isset($sql_desc['key']["$key $type"])) |
| 98 | - sql_alter("TABLE $table ADD $key ($type)",$serveur); |
|
| 98 | + sql_alter("TABLE $table ADD $key ($type)", $serveur); |
|
| 99 | 99 | $last = $field; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * serveur sql |
| 119 | 119 | * @return void |
| 120 | 120 | */ |
| 121 | -function alterer_base($tables_inc, $tables_noinc, $up=false, $serveur='') |
|
| 121 | +function alterer_base($tables_inc, $tables_noinc, $up = false, $serveur = '') |
|
| 122 | 122 | { |
| 123 | 123 | if ($up === false) { |
| 124 | 124 | $old = false; |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | $old = true; |
| 128 | 128 | if (!is_array($up)) $up = array($up); |
| 129 | 129 | } |
| 130 | - foreach($tables_inc as $k => $v) |
|
| 130 | + foreach ($tables_inc as $k => $v) |
|
| 131 | 131 | if (!$old OR in_array($k, $up)) |
| 132 | - creer_ou_upgrader_table($k,$v,true,$old,$serveur); |
|
| 132 | + creer_ou_upgrader_table($k, $v, true, $old, $serveur); |
|
| 133 | 133 | |
| 134 | - foreach($tables_noinc as $k => $v) |
|
| 134 | + foreach ($tables_noinc as $k => $v) |
|
| 135 | 135 | if (!$old OR in_array($k, $up)) |
| 136 | - creer_ou_upgrader_table($k,$v,false,$old,$serveur); |
|
| 136 | + creer_ou_upgrader_table($k, $v, false, $old, $serveur); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | * @param string $serveur |
| 146 | 146 | * @return void |
| 147 | 147 | */ |
| 148 | -function creer_base($serveur='') { |
|
| 148 | +function creer_base($serveur = '') { |
|
| 149 | 149 | |
| 150 | 150 | // Note: les mises a jour reexecutent ce code pour s'assurer |
| 151 | 151 | // de la conformite de la base |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @param string $serveur |
| 167 | 167 | * @return void |
| 168 | 168 | */ |
| 169 | -function maj_tables($upgrade_tables=array(),$serveur=''){ |
|
| 169 | +function maj_tables($upgrade_tables = array(), $serveur = '') { |
|
| 170 | 170 | alterer_base(lister_tables_principales(), |
| 171 | 171 | lister_tables_auxiliaires(), |
| 172 | 172 | $upgrade_tables, |
@@ -29,11 +29,11 @@ discard block |
||
| 29 | 29 | * Sous tableau à merger dans la clé. |
| 30 | 30 | * @return void |
| 31 | 31 | **/ |
| 32 | -function array_set_merge(&$table,$index,$valeur){ |
|
| 32 | +function array_set_merge(&$table, $index, $valeur) { |
|
| 33 | 33 | if (!isset($table[$index])) |
| 34 | 34 | $table[$index] = $valeur; |
| 35 | 35 | else |
| 36 | - $table[$index] = array_merge($table[$index],$valeur); |
|
| 36 | + $table[$index] = array_merge($table[$index], $valeur); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -49,19 +49,19 @@ discard block |
||
| 49 | 49 | * description connue de la table sql demandee |
| 50 | 50 | * @return array|bool |
| 51 | 51 | */ |
| 52 | -function lister_tables_objets_sql($table_sql=null, $desc=array()){ |
|
| 52 | +function lister_tables_objets_sql($table_sql = null, $desc = array()) { |
|
| 53 | 53 | static $deja_la = false; |
| 54 | 54 | static $infos_tables = null; |
| 55 | 55 | static $md5 = null; |
| 56 | 56 | static $plugin_hash = null; |
| 57 | 57 | // prealablement recuperer les tables_principales |
| 58 | 58 | if (is_null($infos_tables) |
| 59 | - OR $plugin_hash!==_PLUGINS_HASH){ |
|
| 59 | + OR $plugin_hash !== _PLUGINS_HASH) { |
|
| 60 | 60 | // pas de reentrance (cas base/serial) |
| 61 | 61 | if ($deja_la) { |
| 62 | - spip_log ("Re-entrance anormale sur lister_tables_objets_sql :" |
|
| 63 | - . var_export(debug_backtrace(),true),_LOG_CRITIQUE); |
|
| 64 | - return ($table_sql==="::md5"?$md5:array()); |
|
| 62 | + spip_log("Re-entrance anormale sur lister_tables_objets_sql :" |
|
| 63 | + . var_export(debug_backtrace(), true), _LOG_CRITIQUE); |
|
| 64 | + return ($table_sql === "::md5" ? $md5 : array()); |
|
| 65 | 65 | } |
| 66 | 66 | $deja_la = true; |
| 67 | 67 | $plugin_hash = _PLUGINS_HASH; // avant de lancer les pipelines |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | 'titre' => 'titre, lang', |
| 89 | 89 | 'date' => 'date', |
| 90 | 90 | 'principale' => 'oui', |
| 91 | - 'champs_editables' => array('surtitre', 'titre', 'soustitre', 'descriptif','nom_site', 'url_site', 'chapo', 'texte', 'ps','virtuel'), |
|
| 91 | + 'champs_editables' => array('surtitre', 'titre', 'soustitre', 'descriptif', 'nom_site', 'url_site', 'chapo', 'texte', 'ps', 'virtuel'), |
|
| 92 | 92 | 'champs_versionnes' => array('id_rubrique', 'surtitre', 'titre', 'soustitre', 'jointure_auteurs', 'descriptif', 'nom_site', 'url_site', 'chapo', 'texte', 'ps'), |
| 93 | 93 | 'field' => array( |
| 94 | 94 | "id_article" => "bigint(21) NOT NULL", |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | 'titre' => "nom AS titre, '' AS lang", |
| 184 | 184 | 'date' => 'date', |
| 185 | 185 | 'principale' => 'oui', |
| 186 | - 'champs_editables' => array('nom','email','bio','nom_site','url_site','imessage','pgp'), |
|
| 186 | + 'champs_editables' => array('nom', 'email', 'bio', 'nom_site', 'url_site', 'imessage', 'pgp'), |
|
| 187 | 187 | 'champs_versionnes' => array('nom', 'bio', 'email', 'nom_site', 'url_site', 'login'), |
| 188 | 188 | 'field' => array( |
| 189 | 189 | "id_auteur" => "bigint(21) NOT NULL", |
@@ -235,14 +235,14 @@ discard block |
||
| 235 | 235 | array('spip_auteurs_liens', 'id_auteur'), |
| 236 | 236 | array( |
| 237 | 237 | 'spip_articles', |
| 238 | - array('id_objet','id_article','objet','article') |
|
| 238 | + array('id_objet', 'id_article', 'objet', 'article') |
|
| 239 | 239 | ), |
| 240 | 240 | 'statut' |
| 241 | 241 | ), |
| 242 | 242 | 'publie' => 'publie', |
| 243 | 243 | 'previsu' => '!', |
| 244 | 244 | 'post_date' => 'date', |
| 245 | - 'exception' => array('statut','lien','tout') |
|
| 245 | + 'exception' => array('statut', 'lien', 'tout') |
|
| 246 | 246 | ), |
| 247 | 247 | ), |
| 248 | 248 | 'statut_images' => array( |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | 'champ' => 'statut', |
| 315 | 315 | 'publie' => 'publie', |
| 316 | 316 | 'previsu' => '!', |
| 317 | - 'exception' => array('statut','tout') |
|
| 317 | + 'exception' => array('statut', 'tout') |
|
| 318 | 318 | ), |
| 319 | 319 | ), |
| 320 | 320 | 'tables_jointures' => array( |
@@ -329,57 +329,57 @@ discard block |
||
| 329 | 329 | // initialiser la signature |
| 330 | 330 | $md5 = md5(serialize($infos_tables)); |
| 331 | 331 | |
| 332 | - $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales',$GLOBALS['tables_principales']); |
|
| 333 | - $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires',$GLOBALS['tables_auxiliaires']); |
|
| 334 | - $infos_tables = pipeline('declarer_tables_objets_sql',$infos_tables); |
|
| 332 | + $GLOBALS['tables_principales'] = pipeline('declarer_tables_principales', $GLOBALS['tables_principales']); |
|
| 333 | + $GLOBALS['tables_auxiliaires'] = pipeline('declarer_tables_auxiliaires', $GLOBALS['tables_auxiliaires']); |
|
| 334 | + $infos_tables = pipeline('declarer_tables_objets_sql', $infos_tables); |
|
| 335 | 335 | |
| 336 | 336 | // completer les informations manquantes ou implicites |
| 337 | 337 | $all = array(); |
| 338 | - foreach(array_keys($infos_tables) as $t) { |
|
| 338 | + foreach (array_keys($infos_tables) as $t) { |
|
| 339 | 339 | // les cles numeriques servent a declarer |
| 340 | 340 | // les proprietes applicables a tous les objets |
| 341 | 341 | // on les mets de cote |
| 342 | 342 | if (is_numeric($t)) { |
| 343 | - $all = array_merge_recursive($all,$infos_tables[$t]); |
|
| 343 | + $all = array_merge_recursive($all, $infos_tables[$t]); |
|
| 344 | 344 | unset($infos_tables[$t]); |
| 345 | 345 | } |
| 346 | 346 | else |
| 347 | - $infos_tables[$t] = renseigner_table_objet_sql($t,$infos_tables[$t]); |
|
| 347 | + $infos_tables[$t] = renseigner_table_objet_sql($t, $infos_tables[$t]); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | // repercuter les proprietes generales communes a tous les objets |
| 351 | - foreach(array_keys($infos_tables) as $t) { |
|
| 352 | - foreach($all as $i=>$v) |
|
| 353 | - if (in_array($i,array('tables_jointures','champs_versionnes'))){ |
|
| 351 | + foreach (array_keys($infos_tables) as $t) { |
|
| 352 | + foreach ($all as $i=>$v) |
|
| 353 | + if (in_array($i, array('tables_jointures', 'champs_versionnes'))) { |
|
| 354 | 354 | $add = $all[$i]; |
| 355 | 355 | // eviter les doublons de declaration de table jointure (ex des mots sur auteurs) |
| 356 | 356 | // pour les declarations generiques avec cles numeriques |
| 357 | - if ($i=='tables_jointures' AND isset($infos_tables[$t][$i]) AND count($infos_tables[$t][$i])) { |
|
| 358 | - $doublons = array_intersect($infos_tables[$t][$i],$add); |
|
| 359 | - foreach($doublons as $d){ |
|
| 360 | - if (is_numeric(array_search($d,$infos_tables[$t][$i])) |
|
| 361 | - AND is_numeric($k=array_search($d,$add))) |
|
| 357 | + if ($i == 'tables_jointures' AND isset($infos_tables[$t][$i]) AND count($infos_tables[$t][$i])) { |
|
| 358 | + $doublons = array_intersect($infos_tables[$t][$i], $add); |
|
| 359 | + foreach ($doublons as $d) { |
|
| 360 | + if (is_numeric(array_search($d, $infos_tables[$t][$i])) |
|
| 361 | + AND is_numeric($k = array_search($d, $add))) |
|
| 362 | 362 | unset($add[$k]); |
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | - $infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i])?$infos_tables[$t][$i]:array(),$add); |
|
| 365 | + $infos_tables[$t][$i] = array_merge(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), $add); |
|
| 366 | 366 | } |
| 367 | 367 | else |
| 368 | - $infos_tables[$t][$i] = array_merge_recursive(isset($infos_tables[$t][$i])?$infos_tables[$t][$i]:array(),$all[$i]); |
|
| 368 | + $infos_tables[$t][$i] = array_merge_recursive(isset($infos_tables[$t][$i]) ? $infos_tables[$t][$i] : array(), $all[$i]); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | // completer les tables principales et auxiliaires |
| 372 | 372 | // avec celles declarees uniquement dans declarer_table_objets_sql |
| 373 | 373 | // pour assurer la compat en transition |
| 374 | - foreach($infos_tables as $table=>$infos) { |
|
| 375 | - $principale_ou_auxiliaire = ($infos['principale']?'tables_principales':'tables_auxiliaires'); |
|
| 374 | + foreach ($infos_tables as $table=>$infos) { |
|
| 375 | + $principale_ou_auxiliaire = ($infos['principale'] ? 'tables_principales' : 'tables_auxiliaires'); |
|
| 376 | 376 | // memoriser des champs eventuels declares par des plugins dans le pipeline tables_xxx |
| 377 | 377 | // qui a ete appelle avant |
| 378 | - $mem = (isset($GLOBALS[$principale_ou_auxiliaire][$table])?$GLOBALS[$principale_ou_auxiliaire][$table]:array()); |
|
| 378 | + $mem = (isset($GLOBALS[$principale_ou_auxiliaire][$table]) ? $GLOBALS[$principale_ou_auxiliaire][$table] : array()); |
|
| 379 | 379 | // l'ajouter au tableau |
| 380 | 380 | $GLOBALS[$principale_ou_auxiliaire][$table] = array(); |
| 381 | - if (isset($infos['field']) AND isset($infos['key'])){ |
|
| 382 | - foreach(array('field','key','join') as $k) |
|
| 381 | + if (isset($infos['field']) AND isset($infos['key'])) { |
|
| 382 | + foreach (array('field', 'key', 'join') as $k) |
|
| 383 | 383 | if (isset($infos_tables[$table][$k])) |
| 384 | 384 | $GLOBALS[$principale_ou_auxiliaire][$table][$k] = &$infos_tables[$table][$k]; |
| 385 | 385 | } |
@@ -388,10 +388,10 @@ discard block |
||
| 388 | 388 | // pour avoir la vrai description en base, il faut passer par trouver_table |
| 389 | 389 | $GLOBALS[$principale_ou_auxiliaire][$table] = array(); |
| 390 | 390 | } |
| 391 | - if (count($mem)){ |
|
| 392 | - foreach(array_keys($mem) as $k) |
|
| 391 | + if (count($mem)) { |
|
| 392 | + foreach (array_keys($mem) as $k) |
|
| 393 | 393 | if (isset($GLOBALS[$principale_ou_auxiliaire][$table][$k])) |
| 394 | - $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge($GLOBALS[$principale_ou_auxiliaire][$table][$k],$mem[$k]); |
|
| 394 | + $GLOBALS[$principale_ou_auxiliaire][$table][$k] = array_merge($GLOBALS[$principale_ou_auxiliaire][$table][$k], $mem[$k]); |
|
| 395 | 395 | else |
| 396 | 396 | $GLOBALS[$principale_ou_auxiliaire][$table][$k] = $mem[$k]; |
| 397 | 397 | } |
@@ -401,23 +401,23 @@ discard block |
||
| 401 | 401 | // on ne le fait que dans un second temps pour que table_objet soit fonctionnel |
| 402 | 402 | // dans le pipeline de declarer_tables_interfaces |
| 403 | 403 | include_spip('public/interfaces'); |
| 404 | - foreach(array_keys($infos_tables) as $t) { |
|
| 405 | - $infos_tables[$t] = renseigner_table_objet_interfaces($t,$infos_tables[$t]); |
|
| 404 | + foreach (array_keys($infos_tables) as $t) { |
|
| 405 | + $infos_tables[$t] = renseigner_table_objet_interfaces($t, $infos_tables[$t]); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | $deja_la = false; |
| 409 | 409 | // signature |
| 410 | 410 | $md5 = md5(serialize($infos_tables)); |
| 411 | 411 | } |
| 412 | - if ($table_sql==="::md5") |
|
| 412 | + if ($table_sql === "::md5") |
|
| 413 | 413 | return $md5; |
| 414 | - if ($table_sql AND !isset($infos_tables[$table_sql])){ |
|
| 414 | + if ($table_sql AND !isset($infos_tables[$table_sql])) { |
|
| 415 | 415 | #$desc = renseigner_table_objet_sql($table_sql,$desc); |
| 416 | - $desc = renseigner_table_objet_interfaces($table_sql,$desc); |
|
| 416 | + $desc = renseigner_table_objet_interfaces($table_sql, $desc); |
|
| 417 | 417 | return $desc; |
| 418 | 418 | } |
| 419 | 419 | if ($table_sql) |
| 420 | - return isset($infos_tables[$table_sql])?$infos_tables[$table_sql]:array(); |
|
| 420 | + return isset($infos_tables[$table_sql]) ? $infos_tables[$table_sql] : array(); |
|
| 421 | 421 | |
| 422 | 422 | return $infos_tables; |
| 423 | 423 | } |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | * Description des tables principales déjà déclarées |
| 433 | 433 | * @return void |
| 434 | 434 | **/ |
| 435 | -function base_serial(&$tables_principales){ |
|
| 435 | +function base_serial(&$tables_principales) { |
|
| 436 | 436 | |
| 437 | 437 | $spip_jobs = array( |
| 438 | 438 | "id_job" => "bigint(21) NOT NULL", |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | * Description des tables auxiliaires déjà déclarées |
| 466 | 466 | * @return void |
| 467 | 467 | **/ |
| 468 | -function base_auxiliaires(&$tables_auxiliaires){ |
|
| 468 | +function base_auxiliaires(&$tables_auxiliaires) { |
|
| 469 | 469 | $spip_resultats = array( |
| 470 | 470 | "recherche" => "char(16) DEFAULT '' NOT NULL", |
| 471 | 471 | "id" => "INT UNSIGNED NOT NULL", |
@@ -578,13 +578,13 @@ discard block |
||
| 578 | 578 | * @param array $infos |
| 579 | 579 | * @return array |
| 580 | 580 | */ |
| 581 | -function renseigner_table_objet_sql($table_sql,&$infos){ |
|
| 582 | - if (!isset($infos['type'])){ |
|
| 581 | +function renseigner_table_objet_sql($table_sql, &$infos) { |
|
| 582 | + if (!isset($infos['type'])) { |
|
| 583 | 583 | // si on arrive de base/trouver_table, on a la cle primaire : |
| 584 | 584 | // s'en servir pour extrapoler le type |
| 585 | - if (isset($infos['key']["PRIMARY KEY"])){ |
|
| 585 | + if (isset($infos['key']["PRIMARY KEY"])) { |
|
| 586 | 586 | $primary = $infos['key']["PRIMARY KEY"]; |
| 587 | - $primary = explode(',',$primary); |
|
| 587 | + $primary = explode(',', $primary); |
|
| 588 | 588 | $primary = reset($primary); |
| 589 | 589 | $infos['type'] = preg_replace(',^spip_|^id_|s$,', '', $primary); |
| 590 | 590 | } |
@@ -600,26 +600,26 @@ discard block |
||
| 600 | 600 | $infos['table_objet_surnoms'] = array(); |
| 601 | 601 | |
| 602 | 602 | if (!isset($infos['principale'])) |
| 603 | - $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql])?'oui':false); |
|
| 603 | + $infos['principale'] = (isset($GLOBALS['tables_principales'][$table_sql]) ? 'oui' : false); |
|
| 604 | 604 | |
| 605 | 605 | // normaliser pour pouvoir tester en php $infos['principale']? |
| 606 | 606 | // et dans une boucle {principale=oui} |
| 607 | - $infos['principale'] = (($infos['principale'] AND $infos['principale']!='non')?'oui':false); |
|
| 607 | + $infos['principale'] = (($infos['principale'] AND $infos['principale'] != 'non') ? 'oui' : false); |
|
| 608 | 608 | |
| 609 | 609 | // declarer et normaliser pour pouvoir tester en php $infos['editable']? |
| 610 | 610 | // et dans une boucle {editable=oui} |
| 611 | 611 | if (!isset($infos['editable'])) $infos['editable'] = 'oui'; |
| 612 | - $infos['editable'] = (($infos['editable'] AND $infos['editable']!='non')?'oui':false); |
|
| 612 | + $infos['editable'] = (($infos['editable'] AND $infos['editable'] != 'non') ? 'oui' : false); |
|
| 613 | 613 | |
| 614 | 614 | // les urls publiques sont par defaut page=type pour les tables principales, et rien pour les autres |
| 615 | 615 | // seules les exceptions sont donc a declarer |
| 616 | 616 | if (!isset($infos['page'])) |
| 617 | - $infos['page'] = ($infos['principale']?$infos['type']:''); |
|
| 617 | + $infos['page'] = ($infos['principale'] ? $infos['type'] : ''); |
|
| 618 | 618 | |
| 619 | 619 | if (!isset($infos['url_voir'])) |
| 620 | 620 | $infos['url_voir'] = $infos['type']; |
| 621 | 621 | if (!isset($infos['url_edit'])) |
| 622 | - $infos['url_edit'] = $infos['url_voir'].($infos['editable']?"_edit":''); |
|
| 622 | + $infos['url_edit'] = $infos['url_voir'].($infos['editable'] ? "_edit" : ''); |
|
| 623 | 623 | if (!isset($infos['icone_objet'])) |
| 624 | 624 | $infos['icone_objet'] = $infos['type']; |
| 625 | 625 | |
@@ -686,27 +686,27 @@ discard block |
||
| 686 | 686 | * @param $infos |
| 687 | 687 | * @return array |
| 688 | 688 | */ |
| 689 | -function renseigner_table_objet_interfaces($table_sql,&$infos){ |
|
| 690 | - if (!isset($infos['titre'])){ |
|
| 689 | +function renseigner_table_objet_interfaces($table_sql, &$infos) { |
|
| 690 | + if (!isset($infos['titre'])) { |
|
| 691 | 691 | if (isset($infos['table_objet']) AND isset($GLOBALS['table_titre'][$infos['table_objet']])) |
| 692 | 692 | $infos['titre'] = $GLOBALS['table_titre'][$infos['table_objet']]; |
| 693 | 693 | else { |
| 694 | - $infos['titre'] = ((isset($infos['field']['titre']))?"titre,":"'' as titre,"); |
|
| 695 | - $infos['titre'] .= ((isset($infos['field']['lang']))?"lang":"'' as lang"); |
|
| 694 | + $infos['titre'] = ((isset($infos['field']['titre'])) ? "titre," : "'' as titre,"); |
|
| 695 | + $infos['titre'] .= ((isset($infos['field']['lang'])) ? "lang" : "'' as lang"); |
|
| 696 | 696 | } |
| 697 | 697 | } |
| 698 | - if (!isset($infos['date'])){ |
|
| 698 | + if (!isset($infos['date'])) { |
|
| 699 | 699 | if (isset($infos['table_objet']) and isset($GLOBALS['table_date'][$infos['table_objet']])) |
| 700 | 700 | $infos['date'] = $GLOBALS['table_date'][$infos['table_objet']]; |
| 701 | 701 | else |
| 702 | - $infos['date'] = ((isset($infos['field']['date']))?"date":''); |
|
| 702 | + $infos['date'] = ((isset($infos['field']['date'])) ? "date" : ''); |
|
| 703 | 703 | } |
| 704 | 704 | if (!isset($infos['statut'])) |
| 705 | 705 | $infos['statut'] = isset($GLOBALS['table_statut'][$table_sql]) ? $GLOBALS['table_statut'][$table_sql] : ''; |
| 706 | 706 | if (!isset($infos['tables_jointures'])) |
| 707 | 707 | $infos['tables_jointures'] = array(); |
| 708 | 708 | if (isset($GLOBALS['tables_jointures'][$table_sql])) |
| 709 | - $infos['tables_jointures'] = array_merge($infos['tables_jointures'],$GLOBALS['tables_jointures'][$table_sql]); |
|
| 709 | + $infos['tables_jointures'] = array_merge($infos['tables_jointures'], $GLOBALS['tables_jointures'][$table_sql]); |
|
| 710 | 710 | return $infos; |
| 711 | 711 | } |
| 712 | 712 | |
@@ -717,9 +717,9 @@ discard block |
||
| 717 | 717 | * @return array |
| 718 | 718 | * Liste et descriptions des tables principales |
| 719 | 719 | **/ |
| 720 | -function lister_tables_principales(){ |
|
| 720 | +function lister_tables_principales() { |
|
| 721 | 721 | static $done = false; |
| 722 | - if (!$done OR !count($GLOBALS['tables_principales'])){ |
|
| 722 | + if (!$done OR !count($GLOBALS['tables_principales'])) { |
|
| 723 | 723 | lister_tables_objets_sql(); |
| 724 | 724 | $done = true; |
| 725 | 725 | } |
@@ -733,9 +733,9 @@ discard block |
||
| 733 | 733 | * @return array |
| 734 | 734 | * Liste et descriptions des tables auxiliaires |
| 735 | 735 | **/ |
| 736 | -function lister_tables_auxiliaires(){ |
|
| 736 | +function lister_tables_auxiliaires() { |
|
| 737 | 737 | static $done = false; |
| 738 | - if (!$done OR !count($GLOBALS['tables_auxiliaires'])){ |
|
| 738 | + if (!$done OR !count($GLOBALS['tables_auxiliaires'])) { |
|
| 739 | 739 | lister_tables_objets_sql(); |
| 740 | 740 | $done = true; |
| 741 | 741 | } |
@@ -746,11 +746,11 @@ discard block |
||
| 746 | 746 | * Recenser les surnoms de table_objet |
| 747 | 747 | * @return array |
| 748 | 748 | */ |
| 749 | -function lister_tables_objets_surnoms(){ |
|
| 749 | +function lister_tables_objets_surnoms() { |
|
| 750 | 750 | static $surnoms = null; |
| 751 | 751 | static $md5 = null; |
| 752 | 752 | if (!$surnoms |
| 753 | - OR $md5 != lister_tables_objets_sql('::md5')){ |
|
| 753 | + OR $md5 != lister_tables_objets_sql('::md5')) { |
|
| 754 | 754 | // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
| 755 | 755 | // pour compatibilite, car il faut dorenavent utiliser |
| 756 | 756 | // declarer_table_objets_sql |
@@ -763,16 +763,16 @@ discard block |
||
| 763 | 763 | 'emb' => 'documents', |
| 764 | 764 | )); |
| 765 | 765 | $infos_tables = lister_tables_objets_sql(); |
| 766 | - foreach($infos_tables as $t=>$infos){ |
|
| 766 | + foreach ($infos_tables as $t=>$infos) { |
|
| 767 | 767 | // cas de base type=>table |
| 768 | 768 | // et preg_replace(',^spip_|^id_|s$,',table)=>table |
| 769 | - if ($infos['table_objet']){ // securite, si la fonction est appelee trop tot, c'est vide |
|
| 769 | + if ($infos['table_objet']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 770 | 770 | // optimisations pour table_objet |
| 771 | 771 | //$surnoms[$infos['type']] = $infos['table_objet']; |
| 772 | 772 | $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['table_objet']; |
| 773 | 773 | $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['table_objet']; |
| 774 | 774 | if (is_array($infos['table_objet_surnoms']) AND count($infos['table_objet_surnoms'])) |
| 775 | - foreach($infos['table_objet_surnoms'] as $surnom) |
|
| 775 | + foreach ($infos['table_objet_surnoms'] as $surnom) |
|
| 776 | 776 | $surnoms[$surnom] = $infos['table_objet']; |
| 777 | 777 | } |
| 778 | 778 | } |
@@ -785,25 +785,25 @@ discard block |
||
| 785 | 785 | * Recenser les surnoms de table_objet |
| 786 | 786 | * @return array |
| 787 | 787 | */ |
| 788 | -function lister_types_surnoms(){ |
|
| 788 | +function lister_types_surnoms() { |
|
| 789 | 789 | static $surnoms = null; |
| 790 | 790 | static $md5 = null; |
| 791 | 791 | if (!$surnoms |
| 792 | - OR $md5 != lister_tables_objets_sql('::md5')){ |
|
| 792 | + OR $md5 != lister_tables_objets_sql('::md5')) { |
|
| 793 | 793 | // passer dans un pipeline qui permet aux plugins de declarer leurs exceptions |
| 794 | 794 | // pour compatibilite, car il faut dorenavent utiliser |
| 795 | 795 | // declarer_table_objets_sql |
| 796 | 796 | $surnoms = pipeline('declarer_type_surnoms', array('racine-site'=>'site')); |
| 797 | 797 | $infos_tables = lister_tables_objets_sql(); |
| 798 | - foreach($infos_tables as $t=>$infos){ |
|
| 799 | - if ($infos['type']){ // securite, si la fonction est appelee trop tot, c'est vide |
|
| 798 | + foreach ($infos_tables as $t=>$infos) { |
|
| 799 | + if ($infos['type']) { // securite, si la fonction est appelee trop tot, c'est vide |
|
| 800 | 800 | // optimisations pour objet_type |
| 801 | 801 | //$surnoms[$infos['type']] = $infos['type']; |
| 802 | 802 | $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['table_objet'])] = $infos['type']; |
| 803 | 803 | $surnoms[preg_replace(',^spip_|^id_|s$,', '', $infos['type'])] = $infos['type']; |
| 804 | 804 | // surnoms declares |
| 805 | 805 | if (is_array($infos['type_surnoms']) AND count($infos['type_surnoms'])) |
| 806 | - foreach($infos['type_surnoms'] as $surnom) |
|
| 806 | + foreach ($infos['type_surnoms'] as $surnom) |
|
| 807 | 807 | $surnoms[$surnom] = $infos['type']; |
| 808 | 808 | } |
| 809 | 809 | } |
@@ -812,31 +812,31 @@ discard block |
||
| 812 | 812 | return $surnoms; |
| 813 | 813 | } |
| 814 | 814 | |
| 815 | -function lister_tables_spip($serveur=''){ |
|
| 815 | +function lister_tables_spip($serveur = '') { |
|
| 816 | 816 | static $tables = array(); |
| 817 | - if (!isset($tables[$serveur])){ |
|
| 817 | + if (!isset($tables[$serveur])) { |
|
| 818 | 818 | $tables[$serveur] = array(); |
| 819 | 819 | if (!function_exists("sql_alltable")) |
| 820 | 820 | include_spip("base/abstract_sql"); |
| 821 | - $ts = sql_alltable(null,$serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 821 | + $ts = sql_alltable(null, $serveur); // toutes les tables "spip_" (ou prefixe perso) |
|
| 822 | 822 | $connexion = $GLOBALS['connexions'][$serveur ? $serveur : 0]; |
| 823 | - $spip = $connexion['prefixe'] . '_'; |
|
| 824 | - foreach ($ts as $t){ |
|
| 825 | - $t = substr($t,strlen($spip)); |
|
| 823 | + $spip = $connexion['prefixe'].'_'; |
|
| 824 | + foreach ($ts as $t) { |
|
| 825 | + $t = substr($t, strlen($spip)); |
|
| 826 | 826 | $tables[$serveur]["spip_$t"] = $t; |
| 827 | 827 | } |
| 828 | 828 | } |
| 829 | 829 | return $tables[$serveur]; |
| 830 | 830 | } |
| 831 | 831 | |
| 832 | -function lister_toutes_tables($serveur){ |
|
| 832 | +function lister_toutes_tables($serveur) { |
|
| 833 | 833 | static $tables = array(); |
| 834 | - if (!isset($tables[$serveur])){ |
|
| 834 | + if (!isset($tables[$serveur])) { |
|
| 835 | 835 | $tables[$serveur] = array(); |
| 836 | 836 | if (!function_exists("sql_alltable")) |
| 837 | 837 | include_spip("base/abstract_sql"); |
| 838 | - $ts = sql_alltable('%',$serveur); // toutes les tables |
|
| 839 | - foreach ($ts as $t){ |
|
| 838 | + $ts = sql_alltable('%', $serveur); // toutes les tables |
|
| 839 | + foreach ($ts as $t) { |
|
| 840 | 840 | $tables[$serveur][$t] = $t; |
| 841 | 841 | } |
| 842 | 842 | } |
@@ -859,32 +859,32 @@ discard block |
||
| 859 | 859 | * @return string |
| 860 | 860 | * Nom de l'objet |
| 861 | 861 | **/ |
| 862 | -function table_objet($type,$serveur='') { |
|
| 862 | +function table_objet($type, $serveur = '') { |
|
| 863 | 863 | $surnoms = lister_tables_objets_surnoms(); |
| 864 | 864 | $type = preg_replace(',^spip_|^id_|s$,', '', $type); |
| 865 | 865 | if (!$type) return; |
| 866 | 866 | if (isset($surnoms[$type])) |
| 867 | 867 | return $surnoms[$type]; |
| 868 | 868 | |
| 869 | - if ($serveur!==false){ |
|
| 870 | - $t=lister_tables_spip($serveur); |
|
| 869 | + if ($serveur !== false) { |
|
| 870 | + $t = lister_tables_spip($serveur); |
|
| 871 | 871 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 872 | - $typetrim = rtrim($type,'s')."s"; |
|
| 872 | + $typetrim = rtrim($type, 's')."s"; |
|
| 873 | 873 | if ( |
| 874 | - (isset($t[$typetrim]) OR in_array($typetrim,$t)) |
|
| 875 | - AND ($desc = $trouver_table(rtrim($type,'s')."s",$serveur)) |
|
| 874 | + (isset($t[$typetrim]) OR in_array($typetrim, $t)) |
|
| 875 | + AND ($desc = $trouver_table(rtrim($type, 's')."s", $serveur)) |
|
| 876 | 876 | ) |
| 877 | 877 | return $desc['id_table']; |
| 878 | 878 | elseif ( |
| 879 | - (isset($t[$type]) OR in_array($type,$t)) |
|
| 880 | - AND ($desc = $trouver_table($type,$serveur)) |
|
| 879 | + (isset($t[$type]) OR in_array($type, $t)) |
|
| 880 | + AND ($desc = $trouver_table($type, $serveur)) |
|
| 881 | 881 | ) |
| 882 | 882 | return $desc['id_table']; |
| 883 | 883 | |
| 884 | - spip_log( 'table_objet('.$type.') calculee sans verification'); |
|
| 884 | + spip_log('table_objet('.$type.') calculee sans verification'); |
|
| 885 | 885 | } |
| 886 | 886 | |
| 887 | - return rtrim($type,'s')."s"; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 887 | + return rtrim($type, 's')."s"; # cas historique ne devant plus servir, sauf si $serveur=false |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | /** |
@@ -903,7 +903,7 @@ discard block |
||
| 903 | 903 | * @return string |
| 904 | 904 | * Nom de la table SQL |
| 905 | 905 | **/ |
| 906 | -function table_objet_sql($type,$serveur='') { |
|
| 906 | +function table_objet_sql($type, $serveur = '') { |
|
| 907 | 907 | global $table_des_tables; |
| 908 | 908 | $nom = table_objet($type, $serveur); |
| 909 | 909 | if (!isset($table_des_tables['articles'])) // eviter de multiples inclusions |
@@ -916,17 +916,17 @@ discard block |
||
| 916 | 916 | $infos_tables = lister_tables_objets_sql(); |
| 917 | 917 | if (isset($infos_tables["spip_$nom"])) |
| 918 | 918 | $nom = "spip_$nom"; |
| 919 | - elseif($serveur!==false) { |
|
| 920 | - $t=lister_tables_spip($serveur); |
|
| 921 | - if (isset($t[$nom]) OR in_array($nom,$t)){ |
|
| 919 | + elseif ($serveur !== false) { |
|
| 920 | + $t = lister_tables_spip($serveur); |
|
| 921 | + if (isset($t[$nom]) OR in_array($nom, $t)) { |
|
| 922 | 922 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 923 | - if ($desc = $trouver_table($nom,$serveur)) |
|
| 923 | + if ($desc = $trouver_table($nom, $serveur)) |
|
| 924 | 924 | return $desc['table_sql']; |
| 925 | 925 | } |
| 926 | 926 | } |
| 927 | 927 | } |
| 928 | 928 | |
| 929 | - return $nom ; |
|
| 929 | + return $nom; |
|
| 930 | 930 | } |
| 931 | 931 | |
| 932 | 932 | /** |
@@ -944,18 +944,18 @@ discard block |
||
| 944 | 944 | * @return string |
| 945 | 945 | * Nom de la clé primaire |
| 946 | 946 | **/ |
| 947 | -function id_table_objet($type,$serveur='') { |
|
| 947 | +function id_table_objet($type, $serveur = '') { |
|
| 948 | 948 | static $trouver_table = null; |
| 949 | - $type = objet_type($type,$serveur); |
|
| 949 | + $type = objet_type($type, $serveur); |
|
| 950 | 950 | if (!$type) return; |
| 951 | 951 | $t = table_objet($type); |
| 952 | 952 | if (!$trouver_table) |
| 953 | 953 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 954 | 954 | |
| 955 | - $ts=lister_tables_spip($serveur); |
|
| 956 | - if (in_array($t,$ts) |
|
| 957 | - OR in_array($t,lister_toutes_tables($serveur))){ |
|
| 958 | - $desc = $trouver_table($t,$serveur); |
|
| 955 | + $ts = lister_tables_spip($serveur); |
|
| 956 | + if (in_array($t, $ts) |
|
| 957 | + OR in_array($t, lister_toutes_tables($serveur))) { |
|
| 958 | + $desc = $trouver_table($t, $serveur); |
|
| 959 | 959 | if (isset($desc['key']['PRIMARY KEY'])) |
| 960 | 960 | return $desc['key']['PRIMARY KEY']; |
| 961 | 961 | if (!$desc OR isset($desc['field']["id_$type"])) |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | * @return string |
| 983 | 983 | * Type de l'objet |
| 984 | 984 | **/ |
| 985 | -function objet_type($table_objet, $serveur=''){ |
|
| 985 | +function objet_type($table_objet, $serveur = '') { |
|
| 986 | 986 | if (!$table_objet) return; |
| 987 | 987 | $surnoms = lister_types_surnoms(); |
| 988 | 988 | |
@@ -995,17 +995,17 @@ discard block |
||
| 995 | 995 | return $surnoms[$type]; |
| 996 | 996 | |
| 997 | 997 | // securite : eliminer les caracteres non \w |
| 998 | - $type = preg_replace(',[^\w-],','',$type); |
|
| 998 | + $type = preg_replace(',[^\w-],', '', $type); |
|
| 999 | 999 | |
| 1000 | 1000 | // si le type redonne bien la table c'est bon |
| 1001 | 1001 | // oui si table_objet ressemblait deja a un type |
| 1002 | - if ( $type==$table_objet |
|
| 1003 | - OR (table_objet($type,$serveur)==$table_objet) |
|
| 1004 | - OR (table_objet_sql($type,$serveur)==$table_objet)) |
|
| 1002 | + if ($type == $table_objet |
|
| 1003 | + OR (table_objet($type, $serveur) == $table_objet) |
|
| 1004 | + OR (table_objet_sql($type, $serveur) == $table_objet)) |
|
| 1005 | 1005 | return $type; |
| 1006 | 1006 | |
| 1007 | 1007 | // si on ne veut pas chercher en base |
| 1008 | - if ($serveur===false) |
|
| 1008 | + if ($serveur === false) |
|
| 1009 | 1009 | return $type; |
| 1010 | 1010 | |
| 1011 | 1011 | // sinon on passe par la cle primaire id_xx pour trouver le type |
@@ -1015,11 +1015,11 @@ discard block |
||
| 1015 | 1015 | // une declaration jeu => jeux, journal => journaux |
| 1016 | 1016 | // dans le pipeline declarer_tables_objets_surnoms |
| 1017 | 1017 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 1018 | - $ts=lister_tables_spip($serveur); |
|
| 1019 | - if (in_array($table_objet,$ts)) |
|
| 1018 | + $ts = lister_tables_spip($serveur); |
|
| 1019 | + if (in_array($table_objet, $ts)) |
|
| 1020 | 1020 | $desc = $trouver_table($table_objet); |
| 1021 | - if (!$desc AND in_array($table_objet=table_objet($type,$serveur),$ts)) |
|
| 1022 | - $desc = $trouver_table($table_objet,$serveur); |
|
| 1021 | + if (!$desc AND in_array($table_objet = table_objet($type, $serveur), $ts)) |
|
| 1022 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 1023 | 1023 | // si le type est declare : bingo ! |
| 1024 | 1024 | if ($desc AND isset($desc['type'])) |
| 1025 | 1025 | return $desc['type']; |
@@ -1040,11 +1040,11 @@ discard block |
||
| 1040 | 1040 | * @param string $serveur |
| 1041 | 1041 | * @return bool |
| 1042 | 1042 | */ |
| 1043 | -function objet_test_si_publie($objet,$id_objet, $serveur=''){ |
|
| 1043 | +function objet_test_si_publie($objet, $id_objet, $serveur = '') { |
|
| 1044 | 1044 | // voir si une fonction est definie pour faire le boulot |
| 1045 | 1045 | // elle a la priorite dans ce cas |
| 1046 | - if ($f = charger_fonction($objet."_test_si_publie","base",true)) |
|
| 1047 | - return $f($objet,$id_objet, $serveur); |
|
| 1046 | + if ($f = charger_fonction($objet."_test_si_publie", "base", true)) |
|
| 1047 | + return $f($objet, $id_objet, $serveur); |
|
| 1048 | 1048 | |
| 1049 | 1049 | // sinon on se fie a la declaration de l'objet si presente |
| 1050 | 1050 | $id_table = $table_objet = table_objet($objet); |
@@ -1052,7 +1052,7 @@ discard block |
||
| 1052 | 1052 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 1053 | 1053 | if ($desc = $trouver_table($table_objet, $serveur) |
| 1054 | 1054 | AND isset($desc['statut']) |
| 1055 | - AND $desc['statut']){ |
|
| 1055 | + AND $desc['statut']) { |
|
| 1056 | 1056 | $boucle = new Boucle(); |
| 1057 | 1057 | $boucle->show = $desc; |
| 1058 | 1058 | $boucle->nom = 'objet_test_si_publie'; |
@@ -1066,7 +1066,7 @@ discard block |
||
| 1066 | 1066 | include_spip('public/compiler'); |
| 1067 | 1067 | include_spip('public/composer'); |
| 1068 | 1068 | instituer_boucle($boucle, false, true); |
| 1069 | - $res = calculer_select($boucle->select,$boucle->from,$boucle->from_type,$boucle->where,$boucle->join,$boucle->group,$boucle->order,$boucle->limit,$boucle->having,$table_objet,$id_table,$serveur); |
|
| 1069 | + $res = calculer_select($boucle->select, $boucle->from, $boucle->from_type, $boucle->where, $boucle->join, $boucle->group, $boucle->order, $boucle->limit, $boucle->having, $table_objet, $id_table, $serveur); |
|
| 1070 | 1070 | if (sql_fetch($res)) |
| 1071 | 1071 | return true; |
| 1072 | 1072 | return false; |
@@ -13,51 +13,51 @@ discard block |
||
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) return; |
| 14 | 14 | |
| 15 | 15 | // http://doc.spip.org/@base_admin_repair_dist |
| 16 | -function base_repair_dist($titre='', $reprise='') { |
|
| 16 | +function base_repair_dist($titre = '', $reprise = '') { |
|
| 17 | 17 | |
| 18 | 18 | $res = admin_repair_tables(); |
| 19 | 19 | if (!$res) { |
| 20 | - $res = "<div class='error'>"._T('avis_erreur_mysql').' '.sql_errno().': '.sql_error() ."</div>\n"; |
|
| 20 | + $res = "<div class='error'>"._T('avis_erreur_mysql').' '.sql_errno().': '.sql_error()."</div>\n"; |
|
| 21 | 21 | } else { |
| 22 | 22 | include_spip('inc/rubriques'); |
| 23 | 23 | calculer_rubriques(); |
| 24 | 24 | propager_les_secteurs(); |
| 25 | 25 | } |
| 26 | 26 | include_spip('inc/minipres'); |
| 27 | - $res .= pipeline('base_admin_repair',$res); |
|
| 27 | + $res .= pipeline('base_admin_repair', $res); |
|
| 28 | 28 | echo minipres(_T('texte_tentative_recuperation'), |
| 29 | - $res . generer_form_ecrire('accueil', '','',_T('public:accueil_site'))); |
|
| 29 | + $res.generer_form_ecrire('accueil', '', '', _T('public:accueil_site'))); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | // http://doc.spip.org/@admin_repair_plat |
| 33 | -function admin_repair_plat(){ |
|
| 34 | - spip_log( "verification des documents joints", _LOG_INFO_IMPORTANTE); |
|
| 33 | +function admin_repair_plat() { |
|
| 34 | + spip_log("verification des documents joints", _LOG_INFO_IMPORTANTE); |
|
| 35 | 35 | $out = ""; |
| 36 | 36 | $repertoire = array(); |
| 37 | 37 | include_spip('inc/getdocument'); |
| 38 | - $res = sql_select('*','spip_documents',"fichier REGEXP CONCAT('^',extension,'[^/\]') AND distant='non'"); |
|
| 38 | + $res = sql_select('*', 'spip_documents', "fichier REGEXP CONCAT('^',extension,'[^/\]') AND distant='non'"); |
|
| 39 | 39 | |
| 40 | - while ($row=sql_fetch($res)){ |
|
| 40 | + while ($row = sql_fetch($res)) { |
|
| 41 | 41 | $ext = $row['extension']; |
| 42 | 42 | if (!$ext) { |
| 43 | - spip_log("document sans extension: " . $row['id_document'], _LOG_INFO_IMPORTANTE); |
|
| 43 | + spip_log("document sans extension: ".$row['id_document'], _LOG_INFO_IMPORTANTE); |
|
| 44 | 44 | continue; |
| 45 | 45 | } |
| 46 | - if (!isset($repertoire[$ext])){ |
|
| 47 | - if (@file_exists($plat = _DIR_IMG. $ext .".plat")) |
|
| 46 | + if (!isset($repertoire[$ext])) { |
|
| 47 | + if (@file_exists($plat = _DIR_IMG.$ext.".plat")) |
|
| 48 | 48 | spip_unlink($plat); |
| 49 | 49 | $repertoire[$ext] = creer_repertoire_documents($ext); |
| 50 | - if (preg_match(',_$,',$repertoire[$ext])) |
|
| 50 | + if (preg_match(',_$,', $repertoire[$ext])) |
|
| 51 | 51 | $repertoire[$ext] = false; |
| 52 | 52 | } |
| 53 | - if ($d=$repertoire[$ext]){ |
|
| 54 | - $d = substr($d,strlen(_DIR_IMG)); |
|
| 53 | + if ($d = $repertoire[$ext]) { |
|
| 54 | + $d = substr($d, strlen(_DIR_IMG)); |
|
| 55 | 55 | $src = $row['fichier']; |
| 56 | - $dest = $d . substr($src,strlen($d)); |
|
| 57 | - if (@copy(_DIR_IMG . $src, _DIR_IMG . $dest) |
|
| 58 | - AND file_exists(_DIR_IMG . $dest)) { |
|
| 59 | - sql_updateq('spip_documents',array('fichier'=>$dest),'id_document='.intval($row['id_document'])); |
|
| 60 | - spip_unlink(_DIR_IMG . $src); |
|
| 56 | + $dest = $d.substr($src, strlen($d)); |
|
| 57 | + if (@copy(_DIR_IMG.$src, _DIR_IMG.$dest) |
|
| 58 | + AND file_exists(_DIR_IMG.$dest)) { |
|
| 59 | + sql_updateq('spip_documents', array('fichier'=>$dest), 'id_document='.intval($row['id_document'])); |
|
| 60 | + spip_unlink(_DIR_IMG.$src); |
|
| 61 | 61 | $out .= "$src => $dest<br />"; |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | // supprimer la meta avant de lancer la reparation |
| 90 | 90 | // car le repair peut etre long ; on ne veut pas boucler |
| 91 | 91 | effacer_meta('admin_repair'); |
| 92 | - if ($repair){ |
|
| 92 | + if ($repair) { |
|
| 93 | 93 | $result_repair = sql_repair($tab); |
| 94 | 94 | if (!$result_repair) return false; |
| 95 | 95 | } |
@@ -99,23 +99,23 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | $count = sql_countsel($tab); |
| 101 | 101 | |
| 102 | - if ($count>1) |
|
| 102 | + if ($count > 1) |
|
| 103 | 103 | $m .= "("._T('texte_compte_elements', array('count' => $count)).")\n"; |
| 104 | - else if ($count==1) |
|
| 104 | + else if ($count == 1) |
|
| 105 | 105 | $m .= "("._T('texte_compte_element', array('count' => $count)).")\n"; |
| 106 | 106 | else |
| 107 | 107 | $m .= "("._T('texte_vide').")\n"; |
| 108 | 108 | |
| 109 | 109 | if ($result_repair |
| 110 | - AND $msg = join(" ", sql_fetch($result_repair)) . ' ' |
|
| 111 | - AND strpos($msg, ' OK ')==FALSE){ |
|
| 110 | + AND $msg = join(" ", sql_fetch($result_repair)).' ' |
|
| 111 | + AND strpos($msg, ' OK ') == FALSE) { |
|
| 112 | 112 | $class = " class='notice'"; |
| 113 | 113 | $m .= "<br /><tt>".spip_htmlentities($msg)."</tt>\n"; |
| 114 | 114 | } |
| 115 | 115 | else |
| 116 | 116 | $m .= " "._T('texte_table_ok'); |
| 117 | 117 | |
| 118 | - $res .="<div$class>$m</div>"; |
|
| 118 | + $res .= "<div$class>$m</div>"; |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | return $res; |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | foreach ($delete as $table) { |
| 22 | 22 | if (sql_drop_table($table)) |
| 23 | 23 | $res[] = $table; |
| 24 | - else spip_log( "SPIP n'a pas pu detruire $table.", _LOG_ERREUR); |
|
| 24 | + else spip_log("SPIP n'a pas pu detruire $table.", _LOG_ERREUR); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // un pipeline pour detruire les tables installees par les plugins |
@@ -35,6 +35,6 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | $d = count($delete); |
| 37 | 37 | $r = count($res); |
| 38 | - spip_log("Tables detruites: $r sur $d: " . join(', ',$res), _LOG_INFO_IMPORTANTE); |
|
| 38 | + spip_log("Tables detruites: $r sur $d: ".join(', ', $res), _LOG_INFO_IMPORTANTE); |
|
| 39 | 39 | } |
| 40 | 40 | ?> |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | // Statut pour articles syndication, pour pouvoir desactiver un article |
| 26 | 26 | spip_query("ALTER TABLE spip_syndic_articles ADD statut VARCHAR(10) NOT NULL"); |
| 27 | 27 | spip_query("UPDATE spip_syndic_articles SET statut='publie'"); |
| 28 | - maj_version (1.3); |
|
| 28 | + maj_version(1.3); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | if (upgrade_vers(1.301, $version_installee, $version_cible)) { |
| 32 | 32 | spip_query("ALTER TABLE spip_forum ADD id_syndic bigint(21) DEFAULT '0' NOT NULL"); |
| 33 | - maj_version (1.301); |
|
| 33 | + maj_version(1.301); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | if (upgrade_vers(1.302, $version_installee, $version_cible)) { |
@@ -38,26 +38,26 @@ discard block |
||
| 38 | 38 | # spip_query("ALTER TABLE spip_forum_cache DROP INDEX fichier"); |
| 39 | 39 | # spip_query("ALTER TABLE spip_forum_cache ADD PRIMARY KEY (fichier, id_forum, id_article, id_rubrique, id_breve, id_syndic)"); |
| 40 | 40 | spip_query("ALTER TABLE spip_forum ADD INDEX id_syndic (id_syndic)"); |
| 41 | - maj_version (1.302); |
|
| 41 | + maj_version(1.302); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | if (upgrade_vers(1.303, $version_installee, $version_cible)) { |
| 45 | 45 | spip_query("ALTER TABLE spip_rubriques ADD date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL"); |
| 46 | 46 | spip_query("ALTER TABLE spip_syndic ADD date_syndic datetime DEFAULT '0000-00-00 00:00:00' NOT NULL"); |
| 47 | 47 | spip_query("UPDATE spip_syndic SET date_syndic=date"); |
| 48 | - maj_version (1.303); |
|
| 48 | + maj_version(1.303); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | if (upgrade_vers(1.306, $version_installee, $version_cible)) { |
| 52 | 52 | spip_query("DROP TABLE spip_index_syndic_articles"); |
| 53 | 53 | spip_query("ALTER TABLE spip_syndic ADD date_index datetime DEFAULT '0000-00-00 00:00:00' NOT NULL"); |
| 54 | 54 | spip_query("ALTER TABLE spip_syndic ADD INDEX date_index (date_index)"); |
| 55 | - maj_version (1.306); |
|
| 55 | + maj_version(1.306); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | if (upgrade_vers(1.307, $version_installee, $version_cible)) { |
| 59 | 59 | spip_query("ALTER TABLE spip_syndic_articles ADD descriptif blob NOT NULL"); |
| 60 | - maj_version (1.307); |
|
| 60 | + maj_version(1.307); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |