@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | * @param string|array $select Champs sélectionnés |
| 338 | 338 | * @param string|array $from Tables sélectionnées |
| 339 | 339 | * @param string|array $where Contraintes |
| 340 | - * @param string|array $groupby Regroupements |
|
| 341 | - * @param string|array $orderby Tris |
|
| 340 | + * @param string $groupby Regroupements |
|
| 341 | + * @param string $orderby Tris |
|
| 342 | 342 | * @param string $limit Limites de résultats |
| 343 | 343 | * @param string|array $having Contraintes posts sélections |
| 344 | 344 | * @param string $serveur Nom de la connexion |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | * @param int $row_number Position. Déplacer le pointeur à cette ligne |
| 971 | 971 | * @param string $serveur Nom de la connexion |
| 972 | 972 | * @param bool $requeter Inutilisé |
| 973 | - * @return bool True si déplacement réussi, false sinon. |
|
| 973 | + * @return boolean|null True si déplacement réussi, false sinon. |
|
| 974 | 974 | **/ |
| 975 | 975 | function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 976 | 976 | if ($r and mysqli_num_rows($r)) { |
@@ -20,11 +20,11 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | if (!defined('_MYSQL_NOPLANES')) { |
| 27 | - define('_MYSQL_NOPLANES', true); |
|
| 27 | + define('_MYSQL_NOPLANES', true); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -41,104 +41,104 @@ discard block |
||
| 41 | 41 | * - tableau décrivant la connexion sinon |
| 42 | 42 | */ |
| 43 | 43 | function req_mysql_dist($host, $port, $login, $pass, $db = '', $prefixe = '') { |
| 44 | - if (!extension_loaded('mysqli')) { |
|
| 45 | - return false; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 49 | - if ( |
|
| 50 | - $port and !is_numeric($socket = $port) |
|
| 51 | - and (!$host or $host=='localhost')) { |
|
| 52 | - $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 53 | - } |
|
| 54 | - elseif ($port) { |
|
| 55 | - $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | - } |
|
| 57 | - else { |
|
| 58 | - $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - if (!$link) { |
|
| 62 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 63 | - |
|
| 64 | - return false; |
|
| 65 | - } |
|
| 66 | - $last = ''; |
|
| 67 | - if (!$db) { |
|
| 68 | - $ok = $link; |
|
| 69 | - $db = 'spip'; |
|
| 70 | - } else { |
|
| 71 | - $ok = mysqli_select_db($link, $db); |
|
| 72 | - if (defined('_MYSQL_SET_SQL_MODE') |
|
| 73 | - or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 74 | - ) { |
|
| 75 | - mysqli_query($link, $last = "set sql_mode=''"); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle" : 'impossible'), |
|
| 80 | - _LOG_DEBUG); |
|
| 81 | - |
|
| 82 | - return !$ok ? false : array( |
|
| 83 | - 'db' => $db, |
|
| 84 | - 'last' => $last, |
|
| 85 | - 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 86 | - 'link' => $link, |
|
| 87 | - 'total_requetes' => 0, |
|
| 88 | - ); |
|
| 44 | + if (!extension_loaded('mysqli')) { |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
|
| 49 | + if ( |
|
| 50 | + $port and !is_numeric($socket = $port) |
|
| 51 | + and (!$host or $host=='localhost')) { |
|
| 52 | + $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
|
| 53 | + } |
|
| 54 | + elseif ($port) { |
|
| 55 | + $link = @mysqli_connect($host, $login, $pass, '', $port); |
|
| 56 | + } |
|
| 57 | + else { |
|
| 58 | + $link = @mysqli_connect($host, $login, $pass); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + if (!$link) { |
|
| 62 | + spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 63 | + |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 66 | + $last = ''; |
|
| 67 | + if (!$db) { |
|
| 68 | + $ok = $link; |
|
| 69 | + $db = 'spip'; |
|
| 70 | + } else { |
|
| 71 | + $ok = mysqli_select_db($link, $db); |
|
| 72 | + if (defined('_MYSQL_SET_SQL_MODE') |
|
| 73 | + or defined('_MYSQL_SQL_MODE_TEXT_NOT_NULL') // compatibilite |
|
| 74 | + ) { |
|
| 75 | + mysqli_query($link, $last = "set sql_mode=''"); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle" : 'impossible'), |
|
| 80 | + _LOG_DEBUG); |
|
| 81 | + |
|
| 82 | + return !$ok ? false : array( |
|
| 83 | + 'db' => $db, |
|
| 84 | + 'last' => $last, |
|
| 85 | + 'prefixe' => $prefixe ? $prefixe : $db, |
|
| 86 | + 'link' => $link, |
|
| 87 | + 'total_requetes' => 0, |
|
| 88 | + ); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | $GLOBALS['spip_mysql_functions_1'] = array( |
| 93 | - 'alter' => 'spip_mysql_alter', |
|
| 94 | - 'count' => 'spip_mysql_count', |
|
| 95 | - 'countsel' => 'spip_mysql_countsel', |
|
| 96 | - 'create' => 'spip_mysql_create', |
|
| 97 | - 'create_base' => 'spip_mysql_create_base', |
|
| 98 | - 'create_view' => 'spip_mysql_create_view', |
|
| 99 | - 'date_proche' => 'spip_mysql_date_proche', |
|
| 100 | - 'delete' => 'spip_mysql_delete', |
|
| 101 | - 'drop_table' => 'spip_mysql_drop_table', |
|
| 102 | - 'drop_view' => 'spip_mysql_drop_view', |
|
| 103 | - 'errno' => 'spip_mysql_errno', |
|
| 104 | - 'error' => 'spip_mysql_error', |
|
| 105 | - 'explain' => 'spip_mysql_explain', |
|
| 106 | - 'fetch' => 'spip_mysql_fetch', |
|
| 107 | - 'seek' => 'spip_mysql_seek', |
|
| 108 | - 'free' => 'spip_mysql_free', |
|
| 109 | - 'hex' => 'spip_mysql_hex', |
|
| 110 | - 'in' => 'spip_mysql_in', |
|
| 111 | - 'insert' => 'spip_mysql_insert', |
|
| 112 | - 'insertq' => 'spip_mysql_insertq', |
|
| 113 | - 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 114 | - 'listdbs' => 'spip_mysql_listdbs', |
|
| 115 | - 'multi' => 'spip_mysql_multi', |
|
| 116 | - 'optimize' => 'spip_mysql_optimize', |
|
| 117 | - 'query' => 'spip_mysql_query', |
|
| 118 | - 'quote' => 'spip_mysql_quote', |
|
| 119 | - 'replace' => 'spip_mysql_replace', |
|
| 120 | - 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 121 | - 'repair' => 'spip_mysql_repair', |
|
| 122 | - 'select' => 'spip_mysql_select', |
|
| 123 | - 'selectdb' => 'spip_mysql_selectdb', |
|
| 124 | - 'set_charset' => 'spip_mysql_set_charset', |
|
| 125 | - 'get_charset' => 'spip_mysql_get_charset', |
|
| 126 | - 'showbase' => 'spip_mysql_showbase', |
|
| 127 | - 'showtable' => 'spip_mysql_showtable', |
|
| 128 | - 'update' => 'spip_mysql_update', |
|
| 129 | - 'updateq' => 'spip_mysql_updateq', |
|
| 130 | - |
|
| 131 | - // association de chaque nom http d'un charset aux couples MySQL |
|
| 132 | - 'charsets' => array( |
|
| 133 | - 'cp1250' => array('charset' => 'cp1250', 'collation' => 'cp1250_general_ci'), |
|
| 134 | - 'cp1251' => array('charset' => 'cp1251', 'collation' => 'cp1251_general_ci'), |
|
| 135 | - 'cp1256' => array('charset' => 'cp1256', 'collation' => 'cp1256_general_ci'), |
|
| 136 | - 'iso-8859-1' => array('charset' => 'latin1', 'collation' => 'latin1_swedish_ci'), |
|
| 93 | + 'alter' => 'spip_mysql_alter', |
|
| 94 | + 'count' => 'spip_mysql_count', |
|
| 95 | + 'countsel' => 'spip_mysql_countsel', |
|
| 96 | + 'create' => 'spip_mysql_create', |
|
| 97 | + 'create_base' => 'spip_mysql_create_base', |
|
| 98 | + 'create_view' => 'spip_mysql_create_view', |
|
| 99 | + 'date_proche' => 'spip_mysql_date_proche', |
|
| 100 | + 'delete' => 'spip_mysql_delete', |
|
| 101 | + 'drop_table' => 'spip_mysql_drop_table', |
|
| 102 | + 'drop_view' => 'spip_mysql_drop_view', |
|
| 103 | + 'errno' => 'spip_mysql_errno', |
|
| 104 | + 'error' => 'spip_mysql_error', |
|
| 105 | + 'explain' => 'spip_mysql_explain', |
|
| 106 | + 'fetch' => 'spip_mysql_fetch', |
|
| 107 | + 'seek' => 'spip_mysql_seek', |
|
| 108 | + 'free' => 'spip_mysql_free', |
|
| 109 | + 'hex' => 'spip_mysql_hex', |
|
| 110 | + 'in' => 'spip_mysql_in', |
|
| 111 | + 'insert' => 'spip_mysql_insert', |
|
| 112 | + 'insertq' => 'spip_mysql_insertq', |
|
| 113 | + 'insertq_multi' => 'spip_mysql_insertq_multi', |
|
| 114 | + 'listdbs' => 'spip_mysql_listdbs', |
|
| 115 | + 'multi' => 'spip_mysql_multi', |
|
| 116 | + 'optimize' => 'spip_mysql_optimize', |
|
| 117 | + 'query' => 'spip_mysql_query', |
|
| 118 | + 'quote' => 'spip_mysql_quote', |
|
| 119 | + 'replace' => 'spip_mysql_replace', |
|
| 120 | + 'replace_multi' => 'spip_mysql_replace_multi', |
|
| 121 | + 'repair' => 'spip_mysql_repair', |
|
| 122 | + 'select' => 'spip_mysql_select', |
|
| 123 | + 'selectdb' => 'spip_mysql_selectdb', |
|
| 124 | + 'set_charset' => 'spip_mysql_set_charset', |
|
| 125 | + 'get_charset' => 'spip_mysql_get_charset', |
|
| 126 | + 'showbase' => 'spip_mysql_showbase', |
|
| 127 | + 'showtable' => 'spip_mysql_showtable', |
|
| 128 | + 'update' => 'spip_mysql_update', |
|
| 129 | + 'updateq' => 'spip_mysql_updateq', |
|
| 130 | + |
|
| 131 | + // association de chaque nom http d'un charset aux couples MySQL |
|
| 132 | + 'charsets' => array( |
|
| 133 | + 'cp1250' => array('charset' => 'cp1250', 'collation' => 'cp1250_general_ci'), |
|
| 134 | + 'cp1251' => array('charset' => 'cp1251', 'collation' => 'cp1251_general_ci'), |
|
| 135 | + 'cp1256' => array('charset' => 'cp1256', 'collation' => 'cp1256_general_ci'), |
|
| 136 | + 'iso-8859-1' => array('charset' => 'latin1', 'collation' => 'latin1_swedish_ci'), |
|
| 137 | 137 | //'iso-8859-6'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 138 | - 'iso-8859-9' => array('charset' => 'latin5', 'collation' => 'latin5_turkish_ci'), |
|
| 138 | + 'iso-8859-9' => array('charset' => 'latin5', 'collation' => 'latin5_turkish_ci'), |
|
| 139 | 139 | //'iso-8859-15'=>array('charset'=>'latin1','collation'=>'latin1_swedish_ci'), |
| 140 | - 'utf-8' => array('charset' => 'utf8', 'collation' => 'utf8_general_ci') |
|
| 141 | - ) |
|
| 140 | + 'utf-8' => array('charset' => 'utf8', 'collation' => 'utf8_general_ci') |
|
| 141 | + ) |
|
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | 144 | |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | * @return Object Information de connexion pour mysqli |
| 150 | 150 | */ |
| 151 | 151 | function _mysql_link($serveur = '') { |
| 152 | - $link = &$GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 152 | + $link = &$GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 153 | 153 | |
| 154 | - return $link; |
|
| 154 | + return $link; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
@@ -164,10 +164,10 @@ discard block |
||
| 164 | 164 | * @return resource Ressource de résultats pour fetch() |
| 165 | 165 | */ |
| 166 | 166 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 167 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 168 | - spip_log("changement de charset sql : " . "SET NAMES " . _q($charset), _LOG_DEBUG); |
|
| 167 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 168 | + spip_log("changement de charset sql : " . "SET NAMES " . _q($charset), _LOG_DEBUG); |
|
| 169 | 169 | |
| 170 | - return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES " . _q($charset)); |
|
| 170 | + return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES " . _q($charset)); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | * @return array Description du charset (son nom est dans 'charset') |
| 181 | 181 | */ |
| 182 | 182 | function spip_mysql_get_charset($charset = array(), $serveur = '', $requeter = true) { |
| 183 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 184 | - $connexion['last'] = $c = "SHOW CHARACTER SET" |
|
| 185 | - . (!$charset ? '' : (" LIKE " . _q($charset['charset']))); |
|
| 183 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 184 | + $connexion['last'] = $c = "SHOW CHARACTER SET" |
|
| 185 | + . (!$charset ? '' : (" LIKE " . _q($charset['charset']))); |
|
| 186 | 186 | |
| 187 | - return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 187 | + return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @return Resource Ressource pour fetch() |
| 200 | 200 | **/ |
| 201 | 201 | function spip_query_db($query, $serveur = '', $requeter = true) { |
| 202 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 202 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -216,66 +216,66 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | function spip_mysql_query($query, $serveur = '', $requeter = true) { |
| 218 | 218 | |
| 219 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 220 | - $prefixe = $connexion['prefixe']; |
|
| 221 | - $link = $connexion['link']; |
|
| 222 | - $db = $connexion['db']; |
|
| 223 | - |
|
| 224 | - $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 225 | - |
|
| 226 | - // renvoyer la requete inerte si demandee |
|
| 227 | - if (!$requeter) { |
|
| 228 | - return $query; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - if (isset($_GET['var_profile'])) { |
|
| 232 | - include_spip('public/tracer'); |
|
| 233 | - $t = trace_query_start(); |
|
| 234 | - } else { |
|
| 235 | - $t = 0; |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - $connexion['last'] = $query; |
|
| 239 | - $connexion['total_requetes']++; |
|
| 240 | - |
|
| 241 | - // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 242 | - $debug = ''; |
|
| 243 | - if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 244 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 245 | - list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | - $debug .= "BOUCLE$id @ " . (isset($infos[0]) ? $infos[0] : '') . " | "; |
|
| 247 | - } |
|
| 248 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 249 | - $debug .= $_SERVER['REQUEST_URI']; |
|
| 250 | - } |
|
| 251 | - if (!empty($GLOBALS['ip'])) { |
|
| 252 | - $debug .= ' + ' . $GLOBALS['ip']; |
|
| 253 | - } |
|
| 254 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - $r = mysqli_query($link, $query . $debug); |
|
| 258 | - |
|
| 259 | - //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 260 | - if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 261 | - if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 262 | - //Fermer la connexion defaillante |
|
| 263 | - mysqli_close($connexion['link']); |
|
| 264 | - unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 265 | - //Relancer une connexion vierge |
|
| 266 | - spip_connect($serveur); |
|
| 267 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 268 | - $link = $connexion['link']; |
|
| 269 | - //On retente au cas où |
|
| 270 | - $r = mysqli_query($link, $query . $debug); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Log de l'erreur eventuelle |
|
| 275 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 276 | - $e .= spip_mysql_error($query, $serveur); |
|
| 277 | - } // et du fautif |
|
| 278 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 219 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 220 | + $prefixe = $connexion['prefixe']; |
|
| 221 | + $link = $connexion['link']; |
|
| 222 | + $db = $connexion['db']; |
|
| 223 | + |
|
| 224 | + $query = _mysql_traite_query($query, $db, $prefixe); |
|
| 225 | + |
|
| 226 | + // renvoyer la requete inerte si demandee |
|
| 227 | + if (!$requeter) { |
|
| 228 | + return $query; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + if (isset($_GET['var_profile'])) { |
|
| 232 | + include_spip('public/tracer'); |
|
| 233 | + $t = trace_query_start(); |
|
| 234 | + } else { |
|
| 235 | + $t = 0; |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + $connexion['last'] = $query; |
|
| 239 | + $connexion['total_requetes']++; |
|
| 240 | + |
|
| 241 | + // ajouter un debug utile dans log/mysql-slow.log ? |
|
| 242 | + $debug = ''; |
|
| 243 | + if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
|
| 244 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 245 | + list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | + $debug .= "BOUCLE$id @ " . (isset($infos[0]) ? $infos[0] : '') . " | "; |
|
| 247 | + } |
|
| 248 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 249 | + $debug .= $_SERVER['REQUEST_URI']; |
|
| 250 | + } |
|
| 251 | + if (!empty($GLOBALS['ip'])) { |
|
| 252 | + $debug .= ' + ' . $GLOBALS['ip']; |
|
| 253 | + } |
|
| 254 | + $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + $r = mysqli_query($link, $query . $debug); |
|
| 258 | + |
|
| 259 | + //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
|
| 260 | + if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
|
| 261 | + if ($e == 2006) { //Si Gone Away on relance une connexion vierge |
|
| 262 | + //Fermer la connexion defaillante |
|
| 263 | + mysqli_close($connexion['link']); |
|
| 264 | + unset($GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]); |
|
| 265 | + //Relancer une connexion vierge |
|
| 266 | + spip_connect($serveur); |
|
| 267 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 268 | + $link = $connexion['link']; |
|
| 269 | + //On retente au cas où |
|
| 270 | + $r = mysqli_query($link, $query . $debug); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Log de l'erreur eventuelle |
|
| 275 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 276 | + $e .= spip_mysql_error($query, $serveur); |
|
| 277 | + } // et du fautif |
|
| 278 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
@@ -290,12 +290,12 @@ discard block |
||
| 290 | 290 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 291 | 291 | */ |
| 292 | 292 | function spip_mysql_alter($query, $serveur = '', $requeter = true) { |
| 293 | - // ici on supprime les ` entourant le nom de table pour permettre |
|
| 294 | - // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 295 | - // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 296 | - $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
|
| 293 | + // ici on supprime les ` entourant le nom de table pour permettre |
|
| 294 | + // la transposition du prefixe, compte tenu que les plugins ont la mauvaise habitude |
|
| 295 | + // d'utiliser ceux-ci, copie-colle de phpmyadmin |
|
| 296 | + $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
|
| 297 | 297 | |
| 298 | - return spip_mysql_query("ALTER " . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 298 | + return spip_mysql_query("ALTER " . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
@@ -308,9 +308,9 @@ discard block |
||
| 308 | 308 | * @return bool Toujours true |
| 309 | 309 | */ |
| 310 | 310 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 311 | - spip_mysql_query("OPTIMIZE TABLE " . $table); |
|
| 311 | + spip_mysql_query("OPTIMIZE TABLE " . $table); |
|
| 312 | 312 | |
| 313 | - return true; |
|
| 313 | + return true; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | |
@@ -323,18 +323,18 @@ discard block |
||
| 323 | 323 | * @return array Tableau de l'explication |
| 324 | 324 | */ |
| 325 | 325 | function spip_mysql_explain($query, $serveur = '', $requeter = true) { |
| 326 | - if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 327 | - return array(); |
|
| 328 | - } |
|
| 329 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 330 | - $prefixe = $connexion['prefixe']; |
|
| 331 | - $link = $connexion['link']; |
|
| 332 | - $db = $connexion['db']; |
|
| 333 | - |
|
| 334 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 335 | - $r = mysqli_query($link, $query); |
|
| 336 | - |
|
| 337 | - return spip_mysql_fetch($r, null, $serveur); |
|
| 326 | + if (strpos(ltrim($query), 'SELECT') !== 0) { |
|
| 327 | + return array(); |
|
| 328 | + } |
|
| 329 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 330 | + $prefixe = $connexion['prefixe']; |
|
| 331 | + $link = $connexion['link']; |
|
| 332 | + $db = $connexion['db']; |
|
| 333 | + |
|
| 334 | + $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 335 | + $r = mysqli_query($link, $query); |
|
| 336 | + |
|
| 337 | + return spip_mysql_fetch($r, null, $serveur); |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | |
@@ -363,35 +363,35 @@ discard block |
||
| 363 | 363 | * - array : Tableau décrivant requête et temps d'exécution si var_profile actif pour tracer. |
| 364 | 364 | */ |
| 365 | 365 | function spip_mysql_select( |
| 366 | - $select, |
|
| 367 | - $from, |
|
| 368 | - $where = '', |
|
| 369 | - $groupby = '', |
|
| 370 | - $orderby = '', |
|
| 371 | - $limit = '', |
|
| 372 | - $having = '', |
|
| 373 | - $serveur = '', |
|
| 374 | - $requeter = true |
|
| 366 | + $select, |
|
| 367 | + $from, |
|
| 368 | + $where = '', |
|
| 369 | + $groupby = '', |
|
| 370 | + $orderby = '', |
|
| 371 | + $limit = '', |
|
| 372 | + $having = '', |
|
| 373 | + $serveur = '', |
|
| 374 | + $requeter = true |
|
| 375 | 375 | ) { |
| 376 | 376 | |
| 377 | 377 | |
| 378 | - $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 379 | - $query = |
|
| 380 | - calculer_mysql_expression('SELECT', $select, ', ') |
|
| 381 | - . calculer_mysql_expression('FROM', $from, ', ') |
|
| 382 | - . calculer_mysql_expression('WHERE', $where) |
|
| 383 | - . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 384 | - . calculer_mysql_expression('HAVING', $having) |
|
| 385 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 386 | - . ($limit ? "\nLIMIT $limit" : ''); |
|
| 378 | + $from = (!is_array($from) ? $from : spip_mysql_select_as($from)); |
|
| 379 | + $query = |
|
| 380 | + calculer_mysql_expression('SELECT', $select, ', ') |
|
| 381 | + . calculer_mysql_expression('FROM', $from, ', ') |
|
| 382 | + . calculer_mysql_expression('WHERE', $where) |
|
| 383 | + . calculer_mysql_expression('GROUP BY', $groupby, ',') |
|
| 384 | + . calculer_mysql_expression('HAVING', $having) |
|
| 385 | + . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 386 | + . ($limit ? "\nLIMIT $limit" : ''); |
|
| 387 | 387 | |
| 388 | - // renvoyer la requete inerte si demandee |
|
| 389 | - if ($requeter === false) { |
|
| 390 | - return $query; |
|
| 391 | - } |
|
| 392 | - $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 388 | + // renvoyer la requete inerte si demandee |
|
| 389 | + if ($requeter === false) { |
|
| 390 | + return $query; |
|
| 391 | + } |
|
| 392 | + $r = spip_mysql_query($query, $serveur, $requeter); |
|
| 393 | 393 | |
| 394 | - return $r ? $r : $query; |
|
| 394 | + return $r ? $r : $query; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | |
@@ -408,7 +408,7 @@ discard block |
||
| 408 | 408 | * @return string Texte du orderby préparé |
| 409 | 409 | */ |
| 410 | 410 | function spip_mysql_order($orderby) { |
| 411 | - return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 411 | + return (is_array($orderby)) ? join(", ", $orderby) : $orderby; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
@@ -431,26 +431,26 @@ discard block |
||
| 431 | 431 | * Contrainte pour clause WHERE |
| 432 | 432 | */ |
| 433 | 433 | function calculer_mysql_where($v) { |
| 434 | - if (!is_array($v)) { |
|
| 435 | - return $v; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - $op = array_shift($v); |
|
| 439 | - if (!($n = count($v))) { |
|
| 440 | - return $op; |
|
| 441 | - } else { |
|
| 442 | - $arg = calculer_mysql_where(array_shift($v)); |
|
| 443 | - if ($n == 1) { |
|
| 444 | - return "$op($arg)"; |
|
| 445 | - } else { |
|
| 446 | - $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 447 | - if ($n == 2) { |
|
| 448 | - return "($arg $op $arg2)"; |
|
| 449 | - } else { |
|
| 450 | - return "($arg $op ($arg2) : $v[0])"; |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - } |
|
| 434 | + if (!is_array($v)) { |
|
| 435 | + return $v; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + $op = array_shift($v); |
|
| 439 | + if (!($n = count($v))) { |
|
| 440 | + return $op; |
|
| 441 | + } else { |
|
| 442 | + $arg = calculer_mysql_where(array_shift($v)); |
|
| 443 | + if ($n == 1) { |
|
| 444 | + return "$op($arg)"; |
|
| 445 | + } else { |
|
| 446 | + $arg2 = calculer_mysql_where(array_shift($v)); |
|
| 447 | + if ($n == 2) { |
|
| 448 | + return "($arg $op $arg2)"; |
|
| 449 | + } else { |
|
| 450 | + return "($arg $op ($arg2) : $v[0])"; |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
@@ -465,21 +465,21 @@ discard block |
||
| 465 | 465 | * @return string Texte de l'expression, une partie donc, du texte la requête. |
| 466 | 466 | */ |
| 467 | 467 | function calculer_mysql_expression($expression, $v, $join = 'AND') { |
| 468 | - if (empty($v)) { |
|
| 469 | - return ''; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - $exp = "\n$expression "; |
|
| 473 | - |
|
| 474 | - if (!is_array($v)) { |
|
| 475 | - return $exp . $v; |
|
| 476 | - } else { |
|
| 477 | - if (strtoupper($join) === 'AND') { |
|
| 478 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 479 | - } else { |
|
| 480 | - return $exp . join($join, $v); |
|
| 481 | - } |
|
| 482 | - } |
|
| 468 | + if (empty($v)) { |
|
| 469 | + return ''; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + $exp = "\n$expression "; |
|
| 473 | + |
|
| 474 | + if (!is_array($v)) { |
|
| 475 | + return $exp . $v; |
|
| 476 | + } else { |
|
| 477 | + if (strtoupper($join) === 'AND') { |
|
| 478 | + return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 479 | + } else { |
|
| 480 | + return $exp . join($join, $v); |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | |
@@ -490,26 +490,26 @@ discard block |
||
| 490 | 490 | * @return string Sélection de colonnes pour une clause SELECT |
| 491 | 491 | */ |
| 492 | 492 | function spip_mysql_select_as($args) { |
| 493 | - $res = ''; |
|
| 494 | - foreach ($args as $k => $v) { |
|
| 495 | - if (substr($k, -1) == '@') { |
|
| 496 | - // c'est une jointure qui se refere au from precedent |
|
| 497 | - // pas de virgule |
|
| 498 | - $res .= ' ' . $v; |
|
| 499 | - } else { |
|
| 500 | - if (!is_numeric($k)) { |
|
| 501 | - $p = strpos($v, " "); |
|
| 502 | - if ($p) { |
|
| 503 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 504 | - } else { |
|
| 505 | - $v .= " AS `$k`"; |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - $res .= ', ' . $v; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - return substr($res, 2); |
|
| 493 | + $res = ''; |
|
| 494 | + foreach ($args as $k => $v) { |
|
| 495 | + if (substr($k, -1) == '@') { |
|
| 496 | + // c'est une jointure qui se refere au from precedent |
|
| 497 | + // pas de virgule |
|
| 498 | + $res .= ' ' . $v; |
|
| 499 | + } else { |
|
| 500 | + if (!is_numeric($k)) { |
|
| 501 | + $p = strpos($v, " "); |
|
| 502 | + if ($p) { |
|
| 503 | + $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 504 | + } else { |
|
| 505 | + $v .= " AS `$k`"; |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + $res .= ', ' . $v; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + return substr($res, 2); |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | |
@@ -533,46 +533,46 @@ discard block |
||
| 533 | 533 | */ |
| 534 | 534 | function _mysql_traite_query($query, $db = '', $prefixe = '') { |
| 535 | 535 | |
| 536 | - if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 537 | - $pref = '`' . $db . '`.'; |
|
| 538 | - } else { |
|
| 539 | - $pref = ''; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - if ($prefixe) { |
|
| 543 | - $pref .= $prefixe . "_"; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 547 | - $suite = ''; |
|
| 548 | - } else { |
|
| 549 | - $suite = strstr($query, $regs[0]); |
|
| 550 | - $query = substr($query, 0, -strlen($suite)); |
|
| 551 | - // propager le prefixe en cas de requete imbriquee |
|
| 552 | - // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 553 | - // modifier une requete qui est en fait juste du texte dans un champ |
|
| 554 | - if (stripos($suite, "SELECT") !== false) { |
|
| 555 | - list($suite, $textes) = query_echappe_textes($suite); |
|
| 556 | - if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
|
| 557 | - $suite = $r[1] . _mysql_traite_query($r[2], $db, $prefixe); |
|
| 558 | - } |
|
| 559 | - $suite = query_reinjecte_textes($suite, $textes); |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 563 | - |
|
| 564 | - // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 565 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 566 | - if (defined('_MYSQL_NOPLANES') |
|
| 567 | - and _MYSQL_NOPLANES |
|
| 568 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 569 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8') { |
|
| 570 | - include_spip('inc/charsets'); |
|
| 571 | - $r = utf8_noplanes($r); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 575 | - return $r; |
|
| 536 | + if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
|
| 537 | + $pref = '`' . $db . '`.'; |
|
| 538 | + } else { |
|
| 539 | + $pref = ''; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + if ($prefixe) { |
|
| 543 | + $pref .= $prefixe . "_"; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
|
| 547 | + $suite = ''; |
|
| 548 | + } else { |
|
| 549 | + $suite = strstr($query, $regs[0]); |
|
| 550 | + $query = substr($query, 0, -strlen($suite)); |
|
| 551 | + // propager le prefixe en cas de requete imbriquee |
|
| 552 | + // il faut alors echapper les chaine avant de le faire, pour ne pas risquer de |
|
| 553 | + // modifier une requete qui est en fait juste du texte dans un champ |
|
| 554 | + if (stripos($suite, "SELECT") !== false) { |
|
| 555 | + list($suite, $textes) = query_echappe_textes($suite); |
|
| 556 | + if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
|
| 557 | + $suite = $r[1] . _mysql_traite_query($r[2], $db, $prefixe); |
|
| 558 | + } |
|
| 559 | + $suite = query_reinjecte_textes($suite, $textes); |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 563 | + |
|
| 564 | + // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 565 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 566 | + if (defined('_MYSQL_NOPLANES') |
|
| 567 | + and _MYSQL_NOPLANES |
|
| 568 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 569 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8') { |
|
| 570 | + include_spip('inc/charsets'); |
|
| 571 | + $r = utf8_noplanes($r); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + #spip_log("_mysql_traite_query: " . substr($r,0, 50) . ".... $db, $prefixe", _LOG_DEBUG); |
|
| 575 | + return $r; |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | /** |
@@ -590,13 +590,13 @@ discard block |
||
| 590 | 590 | * - False en cas d'erreur. |
| 591 | 591 | **/ |
| 592 | 592 | function spip_mysql_selectdb($db, $serveur = '', $requeter = true) { |
| 593 | - $link = _mysql_link($serveur); |
|
| 594 | - $ok = mysqli_select_db($link, $db); |
|
| 595 | - if (!$ok) { |
|
| 596 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 597 | - } |
|
| 593 | + $link = _mysql_link($serveur); |
|
| 594 | + $ok = mysqli_select_db($link, $db); |
|
| 595 | + if (!$ok) { |
|
| 596 | + spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 597 | + } |
|
| 598 | 598 | |
| 599 | - return $ok; |
|
| 599 | + return $ok; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | |
@@ -617,14 +617,14 @@ discard block |
||
| 617 | 617 | * Liste de noms de bases de données |
| 618 | 618 | **/ |
| 619 | 619 | function spip_mysql_listdbs($serveur = '', $requeter = true) { |
| 620 | - $dbs = array(); |
|
| 621 | - if ($res = spip_mysql_query("SHOW DATABASES", $serveur)) { |
|
| 622 | - while ($row = mysqli_fetch_assoc($res)) { |
|
| 623 | - $dbs[] = $row['Database']; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - return $dbs; |
|
| 620 | + $dbs = array(); |
|
| 621 | + if ($res = spip_mysql_query("SHOW DATABASES", $serveur)) { |
|
| 622 | + while ($row = mysqli_fetch_assoc($res)) { |
|
| 623 | + $dbs[] = $row['Database']; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + return $dbs; |
|
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | |
@@ -647,72 +647,72 @@ discard block |
||
| 647 | 647 | * - true si la requête réussie, false sinon. |
| 648 | 648 | */ |
| 649 | 649 | function spip_mysql_create( |
| 650 | - $nom, |
|
| 651 | - $champs, |
|
| 652 | - $cles, |
|
| 653 | - $autoinc = false, |
|
| 654 | - $temporary = false, |
|
| 655 | - $serveur = '', |
|
| 656 | - $requeter = true |
|
| 650 | + $nom, |
|
| 651 | + $champs, |
|
| 652 | + $cles, |
|
| 653 | + $autoinc = false, |
|
| 654 | + $temporary = false, |
|
| 655 | + $serveur = '', |
|
| 656 | + $requeter = true |
|
| 657 | 657 | ) { |
| 658 | 658 | |
| 659 | - $query = ''; |
|
| 660 | - $keys = ''; |
|
| 661 | - $s = ''; |
|
| 662 | - $p = ''; |
|
| 663 | - |
|
| 664 | - // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 665 | - // sans les renseigner (laisse le compilo recuperer la description) |
|
| 666 | - if (!is_array($champs) || !is_array($cles)) { |
|
| 667 | - return; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - $res = spip_mysql_query("SELECT version() as v", $serveur); |
|
| 671 | - if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 672 | - spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - foreach ($cles as $k => $v) { |
|
| 676 | - $keys .= "$s\n\t\t$k ($v)"; |
|
| 677 | - if ($k == "PRIMARY KEY") { |
|
| 678 | - $p = $v; |
|
| 679 | - } |
|
| 680 | - $s = ","; |
|
| 681 | - } |
|
| 682 | - $s = ''; |
|
| 683 | - |
|
| 684 | - $character_set = ""; |
|
| 685 | - if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 686 | - $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 687 | - } |
|
| 688 | - if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 689 | - $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - foreach ($champs as $k => $v) { |
|
| 693 | - $v = _mysql_remplacements_definitions_table($v); |
|
| 694 | - if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 695 | - if (preg_match(',(char|text),i', $defs[1]) |
|
| 696 | - and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 697 | - ) { |
|
| 698 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 699 | - } |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - $query .= "$s\n\t\t$k $v" |
|
| 703 | - . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 704 | - ? " auto_increment" |
|
| 705 | - : '' |
|
| 706 | - ); |
|
| 707 | - $s = ","; |
|
| 708 | - } |
|
| 709 | - $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 710 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")" |
|
| 711 | - . " ENGINE=MyISAM" |
|
| 712 | - . ($character_set ? " DEFAULT $character_set" : "") |
|
| 713 | - . "\n"; |
|
| 714 | - |
|
| 715 | - return spip_mysql_query($q, $serveur); |
|
| 659 | + $query = ''; |
|
| 660 | + $keys = ''; |
|
| 661 | + $s = ''; |
|
| 662 | + $p = ''; |
|
| 663 | + |
|
| 664 | + // certains plugins declarent les tables (permet leur inclusion dans le dump) |
|
| 665 | + // sans les renseigner (laisse le compilo recuperer la description) |
|
| 666 | + if (!is_array($champs) || !is_array($cles)) { |
|
| 667 | + return; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + $res = spip_mysql_query("SELECT version() as v", $serveur); |
|
| 671 | + if (($row = mysqli_fetch_array($res)) && (version_compare($row['v'], '5.0', '>='))) { |
|
| 672 | + spip_mysql_query("SET sql_mode=''", $serveur); |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + foreach ($cles as $k => $v) { |
|
| 676 | + $keys .= "$s\n\t\t$k ($v)"; |
|
| 677 | + if ($k == "PRIMARY KEY") { |
|
| 678 | + $p = $v; |
|
| 679 | + } |
|
| 680 | + $s = ","; |
|
| 681 | + } |
|
| 682 | + $s = ''; |
|
| 683 | + |
|
| 684 | + $character_set = ""; |
|
| 685 | + if (@$GLOBALS['meta']['charset_sql_base']) { |
|
| 686 | + $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 687 | + } |
|
| 688 | + if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
|
| 689 | + $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + foreach ($champs as $k => $v) { |
|
| 693 | + $v = _mysql_remplacements_definitions_table($v); |
|
| 694 | + if (preg_match(',([a-z]*\s*(\(\s*[0-9]*\s*\))?(\s*binary)?),i', $v, $defs)) { |
|
| 695 | + if (preg_match(',(char|text),i', $defs[1]) |
|
| 696 | + and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
|
| 697 | + ) { |
|
| 698 | + $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 699 | + } |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + $query .= "$s\n\t\t$k $v" |
|
| 703 | + . (($autoinc && ($p == $k) && preg_match(',\b(big|small|medium)?int\b,i', $v)) |
|
| 704 | + ? " auto_increment" |
|
| 705 | + : '' |
|
| 706 | + ); |
|
| 707 | + $s = ","; |
|
| 708 | + } |
|
| 709 | + $temporary = $temporary ? 'TEMPORARY' : ''; |
|
| 710 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")" |
|
| 711 | + . " ENGINE=MyISAM" |
|
| 712 | + . ($character_set ? " DEFAULT $character_set" : "") |
|
| 713 | + . "\n"; |
|
| 714 | + |
|
| 715 | + return spip_mysql_query($q, $serveur); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | |
@@ -725,25 +725,25 @@ discard block |
||
| 725 | 725 | * Définition SQL adaptée pour MySQL d'un champ de table |
| 726 | 726 | */ |
| 727 | 727 | function _mysql_remplacements_definitions_table($query) { |
| 728 | - // quelques remplacements |
|
| 729 | - $num = "(\s*\([0-9]*\))?"; |
|
| 730 | - $enum = "(\s*\([^\)]*\))?"; |
|
| 731 | - |
|
| 732 | - $remplace = array( |
|
| 733 | - '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 734 | - '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 735 | - ); |
|
| 736 | - |
|
| 737 | - if (is_string($query)) { |
|
| 738 | - $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 739 | - } elseif (is_array($query)) { |
|
| 740 | - $keys = array_keys($remplace); |
|
| 741 | - foreach ($query as $k => $q) { |
|
| 742 | - $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - return $query; |
|
| 728 | + // quelques remplacements |
|
| 729 | + $num = "(\s*\([0-9]*\))?"; |
|
| 730 | + $enum = "(\s*\([^\)]*\))?"; |
|
| 731 | + |
|
| 732 | + $remplace = array( |
|
| 733 | + '/VARCHAR(\s*[^\s\(])/is' => 'VARCHAR(255)\\1', |
|
| 734 | + '/^TIMESTAMP($| NULL DEFAULT NULL)/is' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP', |
|
| 735 | + ); |
|
| 736 | + |
|
| 737 | + if (is_string($query)) { |
|
| 738 | + $query = preg_replace(array_keys($remplace), $remplace, $query); |
|
| 739 | + } elseif (is_array($query)) { |
|
| 740 | + $keys = array_keys($remplace); |
|
| 741 | + foreach ($query as $k => $q) { |
|
| 742 | + $query[$k] = preg_replace($keys, $remplace, $q); |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + return $query; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | * @return bool true si la base est créee. |
| 757 | 757 | **/ |
| 758 | 758 | function spip_mysql_create_base($nom, $serveur = '', $requeter = true) { |
| 759 | - return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 759 | + return spip_mysql_query("CREATE DATABASE `$nom`", $serveur, $requeter); |
|
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | |
@@ -777,19 +777,19 @@ discard block |
||
| 777 | 777 | * - string texte de la requête si $requeter vaut false |
| 778 | 778 | */ |
| 779 | 779 | function spip_mysql_create_view($nom, $query_select, $serveur = '', $requeter = true) { |
| 780 | - if (!$query_select) { |
|
| 781 | - return false; |
|
| 782 | - } |
|
| 783 | - // vue deja presente |
|
| 784 | - if (sql_showtable($nom, false, $serveur)) { |
|
| 785 | - spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 780 | + if (!$query_select) { |
|
| 781 | + return false; |
|
| 782 | + } |
|
| 783 | + // vue deja presente |
|
| 784 | + if (sql_showtable($nom, false, $serveur)) { |
|
| 785 | + spip_log("Echec creation d'une vue sql ($nom) car celle-ci existe deja (serveur:$serveur)", _LOG_ERREUR); |
|
| 786 | 786 | |
| 787 | - return false; |
|
| 788 | - } |
|
| 787 | + return false; |
|
| 788 | + } |
|
| 789 | 789 | |
| 790 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 790 | + $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 791 | 791 | |
| 792 | - return spip_mysql_query($query, $serveur, $requeter); |
|
| 792 | + return spip_mysql_query($query, $serveur, $requeter); |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | |
@@ -805,11 +805,11 @@ discard block |
||
| 805 | 805 | * - true si la requête a réussie, false sinon |
| 806 | 806 | */ |
| 807 | 807 | function spip_mysql_drop_table($table, $exist = '', $serveur = '', $requeter = true) { |
| 808 | - if ($exist) { |
|
| 809 | - $exist = " IF EXISTS"; |
|
| 810 | - } |
|
| 808 | + if ($exist) { |
|
| 809 | + $exist = " IF EXISTS"; |
|
| 810 | + } |
|
| 811 | 811 | |
| 812 | - return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 812 | + return spip_mysql_query("DROP TABLE$exist $table", $serveur, $requeter); |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | /** |
@@ -824,11 +824,11 @@ discard block |
||
| 824 | 824 | * - true si la requête a réussie, false sinon |
| 825 | 825 | */ |
| 826 | 826 | function spip_mysql_drop_view($view, $exist = '', $serveur = '', $requeter = true) { |
| 827 | - if ($exist) { |
|
| 828 | - $exist = " IF EXISTS"; |
|
| 829 | - } |
|
| 827 | + if ($exist) { |
|
| 828 | + $exist = " IF EXISTS"; |
|
| 829 | + } |
|
| 830 | 830 | |
| 831 | - return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 831 | + return spip_mysql_query("DROP VIEW$exist $view", $serveur, $requeter); |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | * Ressource à utiliser avec sql_fetch() |
| 846 | 846 | **/ |
| 847 | 847 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 848 | - return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 848 | + return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | /** |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | * - true si la requête a réussie, false sinon |
| 862 | 862 | */ |
| 863 | 863 | function spip_mysql_repair($table, $serveur = '', $requeter = true) { |
| 864 | - return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 864 | + return spip_mysql_query("REPAIR TABLE `$table`", $serveur, $requeter); |
|
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | |
@@ -885,86 +885,86 @@ discard block |
||
| 885 | 885 | * - array description de la table sinon |
| 886 | 886 | */ |
| 887 | 887 | function spip_mysql_showtable($nom_table, $serveur = '', $requeter = true) { |
| 888 | - $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 889 | - if (!$s) { |
|
| 890 | - return ''; |
|
| 891 | - } |
|
| 892 | - if (!$requeter) { |
|
| 893 | - return $s; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - list(, $a) = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 897 | - if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 898 | - $desc = $r[1]; |
|
| 899 | - // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 900 | - // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 901 | - if (preg_match("/^(.*?),([^,]*\sKEY[ (].*)$/s", $desc, $r)) { |
|
| 902 | - $namedkeys = $r[2]; |
|
| 903 | - $desc = $r[1]; |
|
| 904 | - } else { |
|
| 905 | - $namedkeys = ""; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - $fields = array(); |
|
| 909 | - foreach (preg_split("/,\s*`/", $desc) as $v) { |
|
| 910 | - preg_match("/^\s*`?([^`]*)`\s*(.*)/", $v, $r); |
|
| 911 | - $fields[strtolower($r[1])] = $r[2]; |
|
| 912 | - } |
|
| 913 | - $keys = array(); |
|
| 914 | - |
|
| 915 | - foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 916 | - if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/", $v, $r)) { |
|
| 917 | - $k = str_replace("`", '', trim($r[1])); |
|
| 918 | - $t = strtolower(str_replace("`", '', $r[2])); |
|
| 919 | - if ($k && !isset($keys[$k])) { |
|
| 920 | - $keys[$k] = $t; |
|
| 921 | - } else { |
|
| 922 | - $keys[] = $t; |
|
| 923 | - } |
|
| 924 | - } |
|
| 925 | - } |
|
| 926 | - spip_mysql_free($s); |
|
| 927 | - |
|
| 928 | - return array('field' => $fields, 'key' => $keys); |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 932 | - if ($res) { |
|
| 933 | - $nfields = array(); |
|
| 934 | - $nkeys = array(); |
|
| 935 | - while ($val = spip_mysql_fetch($res)) { |
|
| 936 | - $nfields[$val["Field"]] = $val['Type']; |
|
| 937 | - if ($val['Null'] == 'NO') { |
|
| 938 | - $nfields[$val["Field"]] .= ' NOT NULL'; |
|
| 939 | - } |
|
| 940 | - if ($val['Default'] === '0' || $val['Default']) { |
|
| 941 | - if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 942 | - $nfields[$val["Field"]] .= ' DEFAULT ' . $val['Default']; |
|
| 943 | - } else { |
|
| 944 | - $nfields[$val["Field"]] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - if ($val['Extra']) { |
|
| 948 | - $nfields[$val["Field"]] .= ' ' . $val['Extra']; |
|
| 949 | - } |
|
| 950 | - if ($val['Key'] == 'PRI') { |
|
| 951 | - $nkeys['PRIMARY KEY'] = $val["Field"]; |
|
| 952 | - } else { |
|
| 953 | - if ($val['Key'] == 'MUL') { |
|
| 954 | - $nkeys['KEY ' . $val["Field"]] = $val["Field"]; |
|
| 955 | - } else { |
|
| 956 | - if ($val['Key'] == 'UNI') { |
|
| 957 | - $nkeys['UNIQUE KEY ' . $val["Field"]] = $val["Field"]; |
|
| 958 | - } |
|
| 959 | - } |
|
| 960 | - } |
|
| 961 | - } |
|
| 962 | - spip_mysql_free($res); |
|
| 963 | - |
|
| 964 | - return array('field' => $nfields, 'key' => $nkeys); |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - return ""; |
|
| 888 | + $s = spip_mysql_query("SHOW CREATE TABLE `$nom_table`", $serveur, $requeter); |
|
| 889 | + if (!$s) { |
|
| 890 | + return ''; |
|
| 891 | + } |
|
| 892 | + if (!$requeter) { |
|
| 893 | + return $s; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + list(, $a) = mysqli_fetch_array($s, MYSQLI_NUM); |
|
| 897 | + if (preg_match(_MYSQL_RE_SHOW_TABLE, $a, $r)) { |
|
| 898 | + $desc = $r[1]; |
|
| 899 | + // extraction d'une KEY éventuelle en prenant garde de ne pas |
|
| 900 | + // relever un champ dont le nom contient KEY (ex. ID_WHISKEY) |
|
| 901 | + if (preg_match("/^(.*?),([^,]*\sKEY[ (].*)$/s", $desc, $r)) { |
|
| 902 | + $namedkeys = $r[2]; |
|
| 903 | + $desc = $r[1]; |
|
| 904 | + } else { |
|
| 905 | + $namedkeys = ""; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + $fields = array(); |
|
| 909 | + foreach (preg_split("/,\s*`/", $desc) as $v) { |
|
| 910 | + preg_match("/^\s*`?([^`]*)`\s*(.*)/", $v, $r); |
|
| 911 | + $fields[strtolower($r[1])] = $r[2]; |
|
| 912 | + } |
|
| 913 | + $keys = array(); |
|
| 914 | + |
|
| 915 | + foreach (preg_split('/\)\s*(,|$)/', $namedkeys) as $v) { |
|
| 916 | + if (preg_match("/^\s*([^(]*)\(([^(]*(\(\d+\))?)$/", $v, $r)) { |
|
| 917 | + $k = str_replace("`", '', trim($r[1])); |
|
| 918 | + $t = strtolower(str_replace("`", '', $r[2])); |
|
| 919 | + if ($k && !isset($keys[$k])) { |
|
| 920 | + $keys[$k] = $t; |
|
| 921 | + } else { |
|
| 922 | + $keys[] = $t; |
|
| 923 | + } |
|
| 924 | + } |
|
| 925 | + } |
|
| 926 | + spip_mysql_free($s); |
|
| 927 | + |
|
| 928 | + return array('field' => $fields, 'key' => $keys); |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + $res = spip_mysql_query("SHOW COLUMNS FROM `$nom_table`", $serveur); |
|
| 932 | + if ($res) { |
|
| 933 | + $nfields = array(); |
|
| 934 | + $nkeys = array(); |
|
| 935 | + while ($val = spip_mysql_fetch($res)) { |
|
| 936 | + $nfields[$val["Field"]] = $val['Type']; |
|
| 937 | + if ($val['Null'] == 'NO') { |
|
| 938 | + $nfields[$val["Field"]] .= ' NOT NULL'; |
|
| 939 | + } |
|
| 940 | + if ($val['Default'] === '0' || $val['Default']) { |
|
| 941 | + if (preg_match('/[A-Z_]/', $val['Default'])) { |
|
| 942 | + $nfields[$val["Field"]] .= ' DEFAULT ' . $val['Default']; |
|
| 943 | + } else { |
|
| 944 | + $nfields[$val["Field"]] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + if ($val['Extra']) { |
|
| 948 | + $nfields[$val["Field"]] .= ' ' . $val['Extra']; |
|
| 949 | + } |
|
| 950 | + if ($val['Key'] == 'PRI') { |
|
| 951 | + $nkeys['PRIMARY KEY'] = $val["Field"]; |
|
| 952 | + } else { |
|
| 953 | + if ($val['Key'] == 'MUL') { |
|
| 954 | + $nkeys['KEY ' . $val["Field"]] = $val["Field"]; |
|
| 955 | + } else { |
|
| 956 | + if ($val['Key'] == 'UNI') { |
|
| 957 | + $nkeys['UNIQUE KEY ' . $val["Field"]] = $val["Field"]; |
|
| 958 | + } |
|
| 959 | + } |
|
| 960 | + } |
|
| 961 | + } |
|
| 962 | + spip_mysql_free($res); |
|
| 963 | + |
|
| 964 | + return array('field' => $nfields, 'key' => $nkeys); |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + return ""; |
|
| 968 | 968 | } |
| 969 | 969 | |
| 970 | 970 | |
@@ -980,12 +980,12 @@ discard block |
||
| 980 | 980 | * @return array Ligne de résultat |
| 981 | 981 | */ |
| 982 | 982 | function spip_mysql_fetch($r, $t = '', $serveur = '', $requeter = true) { |
| 983 | - if (!$t) { |
|
| 984 | - $t = MYSQLI_ASSOC; |
|
| 985 | - } |
|
| 986 | - if ($r) { |
|
| 987 | - return mysqli_fetch_array($r, $t); |
|
| 988 | - } |
|
| 983 | + if (!$t) { |
|
| 984 | + $t = MYSQLI_ASSOC; |
|
| 985 | + } |
|
| 986 | + if ($r) { |
|
| 987 | + return mysqli_fetch_array($r, $t); |
|
| 988 | + } |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | /** |
@@ -998,9 +998,9 @@ discard block |
||
| 998 | 998 | * @return bool True si déplacement réussi, false sinon. |
| 999 | 999 | **/ |
| 1000 | 1000 | function spip_mysql_seek($r, $row_number, $serveur = '', $requeter = true) { |
| 1001 | - if ($r and mysqli_num_rows($r)) { |
|
| 1002 | - return mysqli_data_seek($r, $row_number); |
|
| 1003 | - } |
|
| 1001 | + if ($r and mysqli_num_rows($r)) { |
|
| 1002 | + return mysqli_data_seek($r, $row_number); |
|
| 1003 | + } |
|
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | |
@@ -1018,26 +1018,26 @@ discard block |
||
| 1018 | 1018 | * - int Nombre de lignes (0 si la requête n'a pas réussie) |
| 1019 | 1019 | **/ |
| 1020 | 1020 | function spip_mysql_countsel( |
| 1021 | - $from = array(), |
|
| 1022 | - $where = array(), |
|
| 1023 | - $groupby = '', |
|
| 1024 | - $having = array(), |
|
| 1025 | - $serveur = '', |
|
| 1026 | - $requeter = true |
|
| 1021 | + $from = array(), |
|
| 1022 | + $where = array(), |
|
| 1023 | + $groupby = '', |
|
| 1024 | + $having = array(), |
|
| 1025 | + $serveur = '', |
|
| 1026 | + $requeter = true |
|
| 1027 | 1027 | ) { |
| 1028 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1029 | - |
|
| 1030 | - $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1031 | - if (!$requeter) { |
|
| 1032 | - return $r; |
|
| 1033 | - } |
|
| 1034 | - if (!$r instanceof mysqli_result) { |
|
| 1035 | - return 0; |
|
| 1036 | - } |
|
| 1037 | - list($c) = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1038 | - mysqli_free_result($r); |
|
| 1039 | - |
|
| 1040 | - return $c; |
|
| 1028 | + $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1029 | + |
|
| 1030 | + $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
|
| 1031 | + if (!$requeter) { |
|
| 1032 | + return $r; |
|
| 1033 | + } |
|
| 1034 | + if (!$r instanceof mysqli_result) { |
|
| 1035 | + return 0; |
|
| 1036 | + } |
|
| 1037 | + list($c) = mysqli_fetch_array($r, MYSQLI_NUM); |
|
| 1038 | + mysqli_free_result($r); |
|
| 1039 | + |
|
| 1040 | + return $c; |
|
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | |
@@ -1060,16 +1060,16 @@ discard block |
||
| 1060 | 1060 | * Erreur eventuelle |
| 1061 | 1061 | **/ |
| 1062 | 1062 | function spip_mysql_error($query = '', $serveur = '', $requeter = true) { |
| 1063 | - $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1064 | - $s = mysqli_error($link); |
|
| 1065 | - if ($s) { |
|
| 1066 | - $trace = debug_backtrace(); |
|
| 1067 | - if ($trace[0]['function'] != "spip_mysql_error") { |
|
| 1068 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - return $s; |
|
| 1063 | + $link = $GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]['link']; |
|
| 1064 | + $s = mysqli_error($link); |
|
| 1065 | + if ($s) { |
|
| 1066 | + $trace = debug_backtrace(); |
|
| 1067 | + if ($trace[0]['function'] != "spip_mysql_error") { |
|
| 1068 | + spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1069 | + } |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + return $s; |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | |
@@ -1084,18 +1084,18 @@ discard block |
||
| 1084 | 1084 | * 0, pas d'erreur. Autre, numéro de l'erreur. |
| 1085 | 1085 | **/ |
| 1086 | 1086 | function spip_mysql_errno($serveur = '', $requeter = true) { |
| 1087 | - $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 1088 | - $s = mysqli_errno($link); |
|
| 1089 | - // 2006 MySQL server has gone away |
|
| 1090 | - // 2013 Lost connection to MySQL server during query |
|
| 1091 | - if (in_array($s, array(2006, 2013))) { |
|
| 1092 | - define('spip_interdire_cache', true); |
|
| 1093 | - } |
|
| 1094 | - if ($s) { |
|
| 1095 | - spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - return $s; |
|
| 1087 | + $link = $GLOBALS['connexions'][$serveur ? $serveur : 0]['link']; |
|
| 1088 | + $s = mysqli_errno($link); |
|
| 1089 | + // 2006 MySQL server has gone away |
|
| 1090 | + // 2013 Lost connection to MySQL server during query |
|
| 1091 | + if (in_array($s, array(2006, 2013))) { |
|
| 1092 | + define('spip_interdire_cache', true); |
|
| 1093 | + } |
|
| 1094 | + if ($s) { |
|
| 1095 | + spip_log("Erreur mysql $s", _LOG_ERREUR); |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + return $s; |
|
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | |
@@ -1109,9 +1109,9 @@ discard block |
||
| 1109 | 1109 | * @return int Nombre de lignes |
| 1110 | 1110 | */ |
| 1111 | 1111 | function spip_mysql_count($r, $serveur = '', $requeter = true) { |
| 1112 | - if ($r) { |
|
| 1113 | - return mysqli_num_rows($r); |
|
| 1114 | - } |
|
| 1112 | + if ($r) { |
|
| 1113 | + return mysqli_num_rows($r); |
|
| 1114 | + } |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | |
@@ -1127,7 +1127,7 @@ discard block |
||
| 1127 | 1127 | * @return bool True si réussi |
| 1128 | 1128 | */ |
| 1129 | 1129 | function spip_mysql_free($r, $serveur = '', $requeter = true) { |
| 1130 | - return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1130 | + return (($r instanceof mysqli_result) ? mysqli_free_result($r) : false); |
|
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | 1133 | |
@@ -1155,47 +1155,47 @@ discard block |
||
| 1155 | 1155 | **/ |
| 1156 | 1156 | function spip_mysql_insert($table, $champs, $valeurs, $desc = array(), $serveur = '', $requeter = true) { |
| 1157 | 1157 | |
| 1158 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1159 | - $link = $connexion['link']; |
|
| 1160 | - $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1161 | - |
|
| 1162 | - // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1163 | - if (defined('_MYSQL_NOPLANES') |
|
| 1164 | - and _MYSQL_NOPLANES |
|
| 1165 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1166 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8') { |
|
| 1167 | - include_spip('inc/charsets'); |
|
| 1168 | - $valeurs = utf8_noplanes($valeurs); |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1172 | - if (!$requeter) { |
|
| 1173 | - return $query; |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - if (isset($_GET['var_profile'])) { |
|
| 1177 | - include_spip('public/tracer'); |
|
| 1178 | - $t = trace_query_start(); |
|
| 1179 | - $e = ''; |
|
| 1180 | - } else { |
|
| 1181 | - $t = 0; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - $connexion['last'] = $query; |
|
| 1185 | - #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1186 | - $r = false; |
|
| 1187 | - if (mysqli_query($link, $query)) { |
|
| 1188 | - $r = mysqli_insert_id($link); |
|
| 1189 | - } else { |
|
| 1190 | - // Log de l'erreur eventuelle |
|
| 1191 | - if ($e = spip_mysql_errno($serveur)) { |
|
| 1192 | - $e .= spip_mysql_error($query, $serveur); |
|
| 1193 | - } // et du fautif |
|
| 1194 | - } |
|
| 1195 | - |
|
| 1196 | - return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1197 | - |
|
| 1198 | - // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1158 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 1159 | + $link = $connexion['link']; |
|
| 1160 | + $table = prefixer_table_spip($table, $connexion['prefixe']); |
|
| 1161 | + |
|
| 1162 | + // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
|
| 1163 | + if (defined('_MYSQL_NOPLANES') |
|
| 1164 | + and _MYSQL_NOPLANES |
|
| 1165 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 1166 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8') { |
|
| 1167 | + include_spip('inc/charsets'); |
|
| 1168 | + $valeurs = utf8_noplanes($valeurs); |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + $query = "INSERT INTO $table $champs VALUES $valeurs"; |
|
| 1172 | + if (!$requeter) { |
|
| 1173 | + return $query; |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + if (isset($_GET['var_profile'])) { |
|
| 1177 | + include_spip('public/tracer'); |
|
| 1178 | + $t = trace_query_start(); |
|
| 1179 | + $e = ''; |
|
| 1180 | + } else { |
|
| 1181 | + $t = 0; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + $connexion['last'] = $query; |
|
| 1185 | + #spip_log($query, 'mysql.'._LOG_DEBUG); |
|
| 1186 | + $r = false; |
|
| 1187 | + if (mysqli_query($link, $query)) { |
|
| 1188 | + $r = mysqli_insert_id($link); |
|
| 1189 | + } else { |
|
| 1190 | + // Log de l'erreur eventuelle |
|
| 1191 | + if ($e = spip_mysql_errno($serveur)) { |
|
| 1192 | + $e .= spip_mysql_error($query, $serveur); |
|
| 1193 | + } // et du fautif |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + return $t ? trace_query_end($query, $t, $r, $e, $serveur) : $r; |
|
| 1197 | + |
|
| 1198 | + // return $r ? $r : (($r===0) ? -1 : 0); pb avec le multi-base. |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | /** |
@@ -1220,20 +1220,20 @@ discard block |
||
| 1220 | 1220 | **/ |
| 1221 | 1221 | function spip_mysql_insertq($table, $couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
| 1222 | 1222 | |
| 1223 | - if (!$desc) { |
|
| 1224 | - $desc = description_table($table, $serveur); |
|
| 1225 | - } |
|
| 1226 | - if (!$desc) { |
|
| 1227 | - $couples = array(); |
|
| 1228 | - } |
|
| 1229 | - $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1223 | + if (!$desc) { |
|
| 1224 | + $desc = description_table($table, $serveur); |
|
| 1225 | + } |
|
| 1226 | + if (!$desc) { |
|
| 1227 | + $couples = array(); |
|
| 1228 | + } |
|
| 1229 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1230 | 1230 | |
| 1231 | - foreach ($couples as $champ => $val) { |
|
| 1232 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1233 | - } |
|
| 1231 | + foreach ($couples as $champ => $val) { |
|
| 1232 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1233 | + } |
|
| 1234 | 1234 | |
| 1235 | - return spip_mysql_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 1236 | - $serveur, $requeter); |
|
| 1235 | + return spip_mysql_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 1236 | + $serveur, $requeter); |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | |
@@ -1258,34 +1258,34 @@ discard block |
||
| 1258 | 1258 | **/ |
| 1259 | 1259 | function spip_mysql_insertq_multi($table, $tab_couples = array(), $desc = array(), $serveur = '', $requeter = true) { |
| 1260 | 1260 | |
| 1261 | - if (!$desc) { |
|
| 1262 | - $desc = description_table($table, $serveur); |
|
| 1263 | - } |
|
| 1264 | - if (!$desc) { |
|
| 1265 | - $tab_couples = array(); |
|
| 1266 | - } |
|
| 1267 | - $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1268 | - |
|
| 1269 | - $cles = "(" . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1270 | - $valeurs = array(); |
|
| 1271 | - $r = false; |
|
| 1272 | - |
|
| 1273 | - // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1274 | - foreach ($tab_couples as $couples) { |
|
| 1275 | - foreach ($couples as $champ => $val) { |
|
| 1276 | - $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1277 | - } |
|
| 1278 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1279 | - if (count($valeurs) >= 100) { |
|
| 1280 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1281 | - $valeurs = array(); |
|
| 1282 | - } |
|
| 1283 | - } |
|
| 1284 | - if (count($valeurs)) { |
|
| 1285 | - $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1286 | - } |
|
| 1287 | - |
|
| 1288 | - return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1261 | + if (!$desc) { |
|
| 1262 | + $desc = description_table($table, $serveur); |
|
| 1263 | + } |
|
| 1264 | + if (!$desc) { |
|
| 1265 | + $tab_couples = array(); |
|
| 1266 | + } |
|
| 1267 | + $fields = isset($desc['field']) ? $desc['field'] : array(); |
|
| 1268 | + |
|
| 1269 | + $cles = "(" . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1270 | + $valeurs = array(); |
|
| 1271 | + $r = false; |
|
| 1272 | + |
|
| 1273 | + // Quoter et Inserer par groupes de 100 max pour eviter un debordement de pile |
|
| 1274 | + foreach ($tab_couples as $couples) { |
|
| 1275 | + foreach ($couples as $champ => $val) { |
|
| 1276 | + $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
|
| 1277 | + } |
|
| 1278 | + $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1279 | + if (count($valeurs) >= 100) { |
|
| 1280 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1281 | + $valeurs = array(); |
|
| 1282 | + } |
|
| 1283 | + } |
|
| 1284 | + if (count($valeurs)) { |
|
| 1285 | + $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
|
| 1286 | + } |
|
| 1287 | + |
|
| 1288 | + return $r; // dans le cas d'une table auto_increment, le dernier insert_id |
|
| 1289 | 1289 | } |
| 1290 | 1290 | |
| 1291 | 1291 | /** |
@@ -1310,17 +1310,17 @@ discard block |
||
| 1310 | 1310 | * - array Tableau décrivant la requête et son temps d'exécution si var_profile est actif |
| 1311 | 1311 | */ |
| 1312 | 1312 | function spip_mysql_update($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1313 | - $set = array(); |
|
| 1314 | - foreach ($champs as $champ => $val) { |
|
| 1315 | - $set[] = $champ . "=$val"; |
|
| 1316 | - } |
|
| 1317 | - if (!empty($set)) { |
|
| 1318 | - return spip_mysql_query( |
|
| 1319 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1320 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1321 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1322 | - $serveur, $requeter); |
|
| 1323 | - } |
|
| 1313 | + $set = array(); |
|
| 1314 | + foreach ($champs as $champ => $val) { |
|
| 1315 | + $set[] = $champ . "=$val"; |
|
| 1316 | + } |
|
| 1317 | + if (!empty($set)) { |
|
| 1318 | + return spip_mysql_query( |
|
| 1319 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1320 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1321 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1322 | + $serveur, $requeter); |
|
| 1323 | + } |
|
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | /** |
@@ -1353,27 +1353,27 @@ discard block |
||
| 1353 | 1353 | */ |
| 1354 | 1354 | function spip_mysql_updateq($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1355 | 1355 | |
| 1356 | - if (!$champs) { |
|
| 1357 | - return; |
|
| 1358 | - } |
|
| 1359 | - if (!$desc) { |
|
| 1360 | - $desc = description_table($table, $serveur); |
|
| 1361 | - } |
|
| 1362 | - if (!$desc) { |
|
| 1363 | - $champs = array(); |
|
| 1364 | - } else { |
|
| 1365 | - $fields = $desc['field']; |
|
| 1366 | - } |
|
| 1367 | - $set = array(); |
|
| 1368 | - foreach ($champs as $champ => $val) { |
|
| 1369 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1370 | - } |
|
| 1371 | - |
|
| 1372 | - return spip_mysql_query( |
|
| 1373 | - calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1374 | - . calculer_mysql_expression('SET', $set, ',') |
|
| 1375 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1376 | - $serveur, $requeter); |
|
| 1356 | + if (!$champs) { |
|
| 1357 | + return; |
|
| 1358 | + } |
|
| 1359 | + if (!$desc) { |
|
| 1360 | + $desc = description_table($table, $serveur); |
|
| 1361 | + } |
|
| 1362 | + if (!$desc) { |
|
| 1363 | + $champs = array(); |
|
| 1364 | + } else { |
|
| 1365 | + $fields = $desc['field']; |
|
| 1366 | + } |
|
| 1367 | + $set = array(); |
|
| 1368 | + foreach ($champs as $champ => $val) { |
|
| 1369 | + $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1370 | + } |
|
| 1371 | + |
|
| 1372 | + return spip_mysql_query( |
|
| 1373 | + calculer_mysql_expression('UPDATE', $table, ',') |
|
| 1374 | + . calculer_mysql_expression('SET', $set, ',') |
|
| 1375 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1376 | + $serveur, $requeter); |
|
| 1377 | 1377 | } |
| 1378 | 1378 | |
| 1379 | 1379 | /** |
@@ -1389,20 +1389,20 @@ discard block |
||
| 1389 | 1389 | * - False en cas d'erreur. |
| 1390 | 1390 | **/ |
| 1391 | 1391 | function spip_mysql_delete($table, $where = '', $serveur = '', $requeter = true) { |
| 1392 | - $res = spip_mysql_query( |
|
| 1393 | - calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1394 | - . calculer_mysql_expression('WHERE', $where), |
|
| 1395 | - $serveur, $requeter); |
|
| 1396 | - if (!$requeter) { |
|
| 1397 | - return $res; |
|
| 1398 | - } |
|
| 1399 | - if ($res) { |
|
| 1400 | - $link = _mysql_link($serveur); |
|
| 1401 | - |
|
| 1402 | - return mysqli_affected_rows($link); |
|
| 1403 | - } else { |
|
| 1404 | - return false; |
|
| 1405 | - } |
|
| 1392 | + $res = spip_mysql_query( |
|
| 1393 | + calculer_mysql_expression('DELETE FROM', $table, ',') |
|
| 1394 | + . calculer_mysql_expression('WHERE', $where), |
|
| 1395 | + $serveur, $requeter); |
|
| 1396 | + if (!$requeter) { |
|
| 1397 | + return $res; |
|
| 1398 | + } |
|
| 1399 | + if ($res) { |
|
| 1400 | + $link = _mysql_link($serveur); |
|
| 1401 | + |
|
| 1402 | + return mysqli_affected_rows($link); |
|
| 1403 | + } else { |
|
| 1404 | + return false; |
|
| 1405 | + } |
|
| 1406 | 1406 | } |
| 1407 | 1407 | |
| 1408 | 1408 | |
@@ -1431,8 +1431,8 @@ discard block |
||
| 1431 | 1431 | * - False en cas d'erreur. |
| 1432 | 1432 | **/ |
| 1433 | 1433 | function spip_mysql_replace($table, $couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1434 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',', |
|
| 1435 | - array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1434 | + return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',', |
|
| 1435 | + array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | |
@@ -1461,14 +1461,14 @@ discard block |
||
| 1461 | 1461 | * - False en cas d'erreur. |
| 1462 | 1462 | **/ |
| 1463 | 1463 | function spip_mysql_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1464 | - $cles = "(" . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1465 | - $valeurs = array(); |
|
| 1466 | - foreach ($tab_couples as $couples) { |
|
| 1467 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1468 | - } |
|
| 1469 | - $valeurs = implode(', ', $valeurs); |
|
| 1470 | - |
|
| 1471 | - return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1464 | + $cles = "(" . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1465 | + $valeurs = array(); |
|
| 1466 | + foreach ($tab_couples as $couples) { |
|
| 1467 | + $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1468 | + } |
|
| 1469 | + $valeurs = implode(', ', $valeurs); |
|
| 1470 | + |
|
| 1471 | + return spip_mysql_query("REPLACE $table $cles VALUES $valeurs", $serveur, $requeter); |
|
| 1472 | 1472 | } |
| 1473 | 1473 | |
| 1474 | 1474 | |
@@ -1483,32 +1483,32 @@ discard block |
||
| 1483 | 1483 | * @return string Texte de sélection pour la requête |
| 1484 | 1484 | */ |
| 1485 | 1485 | function spip_mysql_multi($objet, $lang) { |
| 1486 | - $lengthlang = strlen("[$lang]"); |
|
| 1487 | - $posmulti = "INSTR(" . $objet . ", '<multi>')"; |
|
| 1488 | - $posfinmulti = "INSTR(" . $objet . ", '</multi>')"; |
|
| 1489 | - $debutchaine = "LEFT(" . $objet . ", $posmulti-1)"; |
|
| 1490 | - $finchaine = "RIGHT(" . $objet . ", CHAR_LENGTH(" . $objet . ") -(7+$posfinmulti))"; |
|
| 1491 | - $chainemulti = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1492 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1493 | - $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1494 | - $chainelang = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1495 | - $posfinlang = "INSTR(" . $chainelang . ", '[')"; |
|
| 1496 | - $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1497 | - //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1498 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1499 | - " TRIM(" . $objet . "), " . |
|
| 1500 | - " CONCAT( " . |
|
| 1501 | - " $debutchaine, " . |
|
| 1502 | - " IF( " . |
|
| 1503 | - " $poslang = 0, " . |
|
| 1504 | - " $chainemulti, " . |
|
| 1505 | - " $chainelang" . |
|
| 1506 | - " ), " . |
|
| 1507 | - " $finchaine" . |
|
| 1508 | - " ) " . |
|
| 1509 | - "))) AS multi"; |
|
| 1510 | - |
|
| 1511 | - return $retour; |
|
| 1486 | + $lengthlang = strlen("[$lang]"); |
|
| 1487 | + $posmulti = "INSTR(" . $objet . ", '<multi>')"; |
|
| 1488 | + $posfinmulti = "INSTR(" . $objet . ", '</multi>')"; |
|
| 1489 | + $debutchaine = "LEFT(" . $objet . ", $posmulti-1)"; |
|
| 1490 | + $finchaine = "RIGHT(" . $objet . ", CHAR_LENGTH(" . $objet . ") -(7+$posfinmulti))"; |
|
| 1491 | + $chainemulti = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1492 | + $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1493 | + $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
|
| 1494 | + $chainelang = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1495 | + $posfinlang = "INSTR(" . $chainelang . ", '[')"; |
|
| 1496 | + $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
|
| 1497 | + //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
|
| 1498 | + $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1499 | + " TRIM(" . $objet . "), " . |
|
| 1500 | + " CONCAT( " . |
|
| 1501 | + " $debutchaine, " . |
|
| 1502 | + " IF( " . |
|
| 1503 | + " $poslang = 0, " . |
|
| 1504 | + " $chainemulti, " . |
|
| 1505 | + " $chainelang" . |
|
| 1506 | + " ), " . |
|
| 1507 | + " $finchaine" . |
|
| 1508 | + " ) " . |
|
| 1509 | + "))) AS multi"; |
|
| 1510 | + |
|
| 1511 | + return $retour; |
|
| 1512 | 1512 | } |
| 1513 | 1513 | |
| 1514 | 1514 | /** |
@@ -1522,7 +1522,7 @@ discard block |
||
| 1522 | 1522 | * Valeur hexadécimale pour MySQL |
| 1523 | 1523 | **/ |
| 1524 | 1524 | function spip_mysql_hex($v) { |
| 1525 | - return "0x" . $v; |
|
| 1525 | + return "0x" . $v; |
|
| 1526 | 1526 | } |
| 1527 | 1527 | |
| 1528 | 1528 | /** |
@@ -1538,15 +1538,15 @@ discard block |
||
| 1538 | 1538 | * Donnée prête à être utilisée par le gestionnaire SQL |
| 1539 | 1539 | */ |
| 1540 | 1540 | function spip_mysql_quote($v, $type = '') { |
| 1541 | - if (!is_array($v)) { |
|
| 1542 | - return spip_mysql_cite($v, $type); |
|
| 1543 | - } |
|
| 1544 | - |
|
| 1545 | - // si c'est un tableau, le parcourir en propageant le type |
|
| 1546 | - foreach ($v as $k => $r) { |
|
| 1547 | - $v[$k] = spip_mysql_quote($r, $type); |
|
| 1548 | - } |
|
| 1549 | - return implode(',', $v); |
|
| 1541 | + if (!is_array($v)) { |
|
| 1542 | + return spip_mysql_cite($v, $type); |
|
| 1543 | + } |
|
| 1544 | + |
|
| 1545 | + // si c'est un tableau, le parcourir en propageant le type |
|
| 1546 | + foreach ($v as $k => $r) { |
|
| 1547 | + $v[$k] = spip_mysql_quote($r, $type); |
|
| 1548 | + } |
|
| 1549 | + return implode(',', $v); |
|
| 1550 | 1550 | } |
| 1551 | 1551 | |
| 1552 | 1552 | /** |
@@ -1562,18 +1562,18 @@ discard block |
||
| 1562 | 1562 | * Expression SQL |
| 1563 | 1563 | **/ |
| 1564 | 1564 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1565 | - $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1566 | - return '(' |
|
| 1567 | - . $champ |
|
| 1568 | - . (($interval <= 0) ? '>' : '<') |
|
| 1569 | - . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1570 | - . '(' |
|
| 1571 | - . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1572 | - . ', INTERVAL ' |
|
| 1573 | - . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1574 | - . ' ' |
|
| 1575 | - . $unite |
|
| 1576 | - . '))'; |
|
| 1565 | + $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1566 | + return '(' |
|
| 1567 | + . $champ |
|
| 1568 | + . (($interval <= 0) ? '>' : '<') |
|
| 1569 | + . (($interval <= 0) ? 'DATE_SUB' : 'DATE_ADD') |
|
| 1570 | + . '(' |
|
| 1571 | + . ($use_now ? 'NOW()' : sql_quote(date('Y-m-d H:i:s'))) |
|
| 1572 | + . ', INTERVAL ' |
|
| 1573 | + . (($interval > 0) ? $interval : (0 - $interval)) |
|
| 1574 | + . ' ' |
|
| 1575 | + . $unite |
|
| 1576 | + . '))'; |
|
| 1577 | 1577 | } |
| 1578 | 1578 | |
| 1579 | 1579 | |
@@ -1597,7 +1597,7 @@ discard block |
||
| 1597 | 1597 | * Expression de requête SQL |
| 1598 | 1598 | **/ |
| 1599 | 1599 | function spip_mysql_in($val, $valeurs, $not = '', $serveur = '', $requeter = true) { |
| 1600 | - return "($val $not IN ($valeurs))"; |
|
| 1600 | + return "($val $not IN ($valeurs))"; |
|
| 1601 | 1601 | } |
| 1602 | 1602 | |
| 1603 | 1603 | |
@@ -1609,36 +1609,36 @@ discard block |
||
| 1609 | 1609 | * @return string|number Texte ou nombre échappé |
| 1610 | 1610 | */ |
| 1611 | 1611 | function spip_mysql_cite($v, $type) { |
| 1612 | - if (!$type) { |
|
| 1613 | - if (is_bool($v)) { |
|
| 1614 | - return strval(intval($v)); |
|
| 1615 | - } |
|
| 1616 | - elseif (is_numeric($v)) { |
|
| 1617 | - return strval($v); |
|
| 1618 | - } |
|
| 1619 | - return "'" . addslashes($v) . "'"; |
|
| 1620 | - } |
|
| 1621 | - |
|
| 1622 | - if (is_null($v) |
|
| 1623 | - and stripos($type, "NOT NULL") === false |
|
| 1624 | - ) { |
|
| 1625 | - return 'NULL'; |
|
| 1626 | - } // null php se traduit en NULL SQL |
|
| 1627 | - if (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1628 | - return $v; |
|
| 1629 | - } |
|
| 1630 | - if (sql_test_int($type)) { |
|
| 1631 | - if (is_numeric($v) or (ctype_xdigit(substr($v, 2)) |
|
| 1632 | - and $v[0] == '0' and $v[1] == 'x') |
|
| 1633 | - ) { |
|
| 1634 | - return $v; |
|
| 1635 | - } // si pas numerique, forcer le intval |
|
| 1636 | - else { |
|
| 1637 | - return intval($v); |
|
| 1638 | - } |
|
| 1639 | - } |
|
| 1640 | - |
|
| 1641 | - return ("'" . addslashes($v) . "'"); |
|
| 1612 | + if (!$type) { |
|
| 1613 | + if (is_bool($v)) { |
|
| 1614 | + return strval(intval($v)); |
|
| 1615 | + } |
|
| 1616 | + elseif (is_numeric($v)) { |
|
| 1617 | + return strval($v); |
|
| 1618 | + } |
|
| 1619 | + return "'" . addslashes($v) . "'"; |
|
| 1620 | + } |
|
| 1621 | + |
|
| 1622 | + if (is_null($v) |
|
| 1623 | + and stripos($type, "NOT NULL") === false |
|
| 1624 | + ) { |
|
| 1625 | + return 'NULL'; |
|
| 1626 | + } // null php se traduit en NULL SQL |
|
| 1627 | + if (sql_test_date($type) and preg_match('/^\w+\(/', $v)) { |
|
| 1628 | + return $v; |
|
| 1629 | + } |
|
| 1630 | + if (sql_test_int($type)) { |
|
| 1631 | + if (is_numeric($v) or (ctype_xdigit(substr($v, 2)) |
|
| 1632 | + and $v[0] == '0' and $v[1] == 'x') |
|
| 1633 | + ) { |
|
| 1634 | + return $v; |
|
| 1635 | + } // si pas numerique, forcer le intval |
|
| 1636 | + else { |
|
| 1637 | + return intval($v); |
|
| 1638 | + } |
|
| 1639 | + } |
|
| 1640 | + |
|
| 1641 | + return ("'" . addslashes($v) . "'"); |
|
| 1642 | 1642 | } |
| 1643 | 1643 | |
| 1644 | 1644 | |
@@ -1662,21 +1662,21 @@ discard block |
||
| 1662 | 1662 | */ |
| 1663 | 1663 | function spip_get_lock($nom, $timeout = 0) { |
| 1664 | 1664 | |
| 1665 | - define('_LOCK_TIME', intval(time() / 3600 - 316982)); |
|
| 1665 | + define('_LOCK_TIME', intval(time() / 3600 - 316982)); |
|
| 1666 | 1666 | |
| 1667 | - $connexion = &$GLOBALS['connexions'][0]; |
|
| 1668 | - $bd = $connexion['db']; |
|
| 1669 | - $prefixe = $connexion['prefixe']; |
|
| 1670 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1667 | + $connexion = &$GLOBALS['connexions'][0]; |
|
| 1668 | + $bd = $connexion['db']; |
|
| 1669 | + $prefixe = $connexion['prefixe']; |
|
| 1670 | + $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1671 | 1671 | |
| 1672 | - $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1672 | + $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1673 | 1673 | |
| 1674 | - $q = @sql_fetch(mysqli_query(_mysql_link(), $q)); |
|
| 1675 | - if (!$q) { |
|
| 1676 | - spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1677 | - } |
|
| 1674 | + $q = @sql_fetch(mysqli_query(_mysql_link(), $q)); |
|
| 1675 | + if (!$q) { |
|
| 1676 | + spip_log("pas de lock sql pour $nom", _LOG_ERREUR); |
|
| 1677 | + } |
|
| 1678 | 1678 | |
| 1679 | - return $q['n']; |
|
| 1679 | + return $q['n']; |
|
| 1680 | 1680 | } |
| 1681 | 1681 | |
| 1682 | 1682 | |
@@ -1693,13 +1693,13 @@ discard block |
||
| 1693 | 1693 | */ |
| 1694 | 1694 | function spip_release_lock($nom) { |
| 1695 | 1695 | |
| 1696 | - $connexion = &$GLOBALS['connexions'][0]; |
|
| 1697 | - $bd = $connexion['db']; |
|
| 1698 | - $prefixe = $connexion['prefixe']; |
|
| 1699 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1696 | + $connexion = &$GLOBALS['connexions'][0]; |
|
| 1697 | + $bd = $connexion['db']; |
|
| 1698 | + $prefixe = $connexion['prefixe']; |
|
| 1699 | + $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1700 | 1700 | |
| 1701 | - $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1702 | - mysqli_query(_mysql_link(), $q); |
|
| 1701 | + $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1702 | + mysqli_query(_mysql_link(), $q); |
|
| 1703 | 1703 | } |
| 1704 | 1704 | |
| 1705 | 1705 | |
@@ -1710,7 +1710,7 @@ discard block |
||
| 1710 | 1710 | * True si on a les fonctions, false sinon |
| 1711 | 1711 | */ |
| 1712 | 1712 | function spip_versions_mysql() { |
| 1713 | - return function_exists('mysqli_query'); |
|
| 1713 | + return function_exists('mysqli_query'); |
|
| 1714 | 1714 | } |
| 1715 | 1715 | |
| 1716 | 1716 | |
@@ -1723,20 +1723,20 @@ discard block |
||
| 1723 | 1723 | * - chaîne : code compilé pour le faire désactiver par SPIP sinon |
| 1724 | 1724 | */ |
| 1725 | 1725 | function test_rappel_nom_base_mysql($server_db) { |
| 1726 | - $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1727 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1728 | - $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1726 | + $GLOBALS['mysql_rappel_nom_base'] = true; |
|
| 1727 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1728 | + $ok = spip_query("INSERT INTO spip_meta (nom,valeur) VALUES ('mysql_rappel_nom_base', 'test')", $server_db); |
|
| 1729 | 1729 | |
| 1730 | - if ($ok) { |
|
| 1731 | - sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1730 | + if ($ok) { |
|
| 1731 | + sql_delete('spip_meta', "nom='mysql_rappel_nom_base'", $server_db); |
|
| 1732 | 1732 | |
| 1733 | - return ''; |
|
| 1734 | - } else { |
|
| 1735 | - $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1733 | + return ''; |
|
| 1734 | + } else { |
|
| 1735 | + $GLOBALS['mysql_rappel_nom_base'] = false; |
|
| 1736 | 1736 | |
| 1737 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1738 | - "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1739 | - } |
|
| 1737 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1738 | + "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
|
| 1739 | + } |
|
| 1740 | 1740 | } |
| 1741 | 1741 | |
| 1742 | 1742 | /** |
@@ -1750,13 +1750,13 @@ discard block |
||
| 1750 | 1750 | * - chaîne : code compilé pour l'indiquer le résultat du test à SPIP |
| 1751 | 1751 | */ |
| 1752 | 1752 | function test_sql_mode_mysql($server_db) { |
| 1753 | - $res = sql_select("version() as v", '', '', '', '', '', '', $server_db); |
|
| 1754 | - $row = sql_fetch($res, $server_db); |
|
| 1755 | - if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1756 | - defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1753 | + $res = sql_select("version() as v", '', '', '', '', '', '', $server_db); |
|
| 1754 | + $row = sql_fetch($res, $server_db); |
|
| 1755 | + if (version_compare($row['v'], '5.0.0', '>=')) { |
|
| 1756 | + defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE', true); |
|
| 1757 | 1757 | |
| 1758 | - return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1759 | - } |
|
| 1758 | + return "defined('_MYSQL_SET_SQL_MODE') || define('_MYSQL_SET_SQL_MODE',true);\n"; |
|
| 1759 | + } |
|
| 1760 | 1760 | |
| 1761 | - return ''; |
|
| 1761 | + return ''; |
|
| 1762 | 1762 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | // si port est fourni mais pas host, c'est un socket -> compat avec vieille syntaxe de mysql_connect() et anciens fichiers connect.php |
| 49 | 49 | if ( |
| 50 | 50 | $port and !is_numeric($socket = $port) |
| 51 | - and (!$host or $host=='localhost')) { |
|
| 51 | + and (!$host or $host == 'localhost')) { |
|
| 52 | 52 | $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
| 53 | 53 | } |
| 54 | 54 | elseif ($port) { |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | if (!$link) { |
| 62 | - spip_log('Echec mysqli_connect. Erreur : ' . mysqli_connect_error(), 'mysql.' . _LOG_HS); |
|
| 62 | + spip_log('Echec mysqli_connect. Erreur : '.mysqli_connect_error(), 'mysql.'._LOG_HS); |
|
| 63 | 63 | |
| 64 | 64 | return false; |
| 65 | 65 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe " . ($ok ? "operationnelle" : 'impossible'), |
|
| 79 | + spip_log("Connexion MySQLi vers $host, base $db, prefixe $prefixe ".($ok ? "operationnelle" : 'impossible'), |
|
| 80 | 80 | _LOG_DEBUG); |
| 81 | 81 | |
| 82 | 82 | return !$ok ? false : array( |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | function spip_mysql_set_charset($charset, $serveur = '', $requeter = true) { |
| 167 | 167 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 168 | - spip_log("changement de charset sql : " . "SET NAMES " . _q($charset), _LOG_DEBUG); |
|
| 168 | + spip_log("changement de charset sql : "."SET NAMES "._q($charset), _LOG_DEBUG); |
|
| 169 | 169 | |
| 170 | - return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES " . _q($charset)); |
|
| 170 | + return mysqli_query($connexion['link'], $connexion['last'] = "SET NAMES "._q($charset)); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | function spip_mysql_get_charset($charset = array(), $serveur = '', $requeter = true) { |
| 183 | 183 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 184 | 184 | $connexion['last'] = $c = "SHOW CHARACTER SET" |
| 185 | - . (!$charset ? '' : (" LIKE " . _q($charset['charset']))); |
|
| 185 | + . (!$charset ? '' : (" LIKE "._q($charset['charset']))); |
|
| 186 | 186 | |
| 187 | 187 | return spip_mysql_fetch(mysqli_query($connexion['link'], $c), null, $serveur); |
| 188 | 188 | } |
@@ -242,19 +242,19 @@ discard block |
||
| 242 | 242 | $debug = ''; |
| 243 | 243 | if (defined('_DEBUG_SLOW_QUERIES') and _DEBUG_SLOW_QUERIES) { |
| 244 | 244 | if (isset($GLOBALS['debug']['aucasou'])) { |
| 245 | - list(, $id, , $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | - $debug .= "BOUCLE$id @ " . (isset($infos[0]) ? $infos[0] : '') . " | "; |
|
| 245 | + list(, $id,, $infos) = $GLOBALS['debug']['aucasou']; |
|
| 246 | + $debug .= "BOUCLE$id @ ".(isset($infos[0]) ? $infos[0] : '')." | "; |
|
| 247 | 247 | } |
| 248 | 248 | if (isset($_SERVER['REQUEST_URI'])) { |
| 249 | 249 | $debug .= $_SERVER['REQUEST_URI']; |
| 250 | 250 | } |
| 251 | 251 | if (!empty($GLOBALS['ip'])) { |
| 252 | - $debug .= ' + ' . $GLOBALS['ip']; |
|
| 252 | + $debug .= ' + '.$GLOBALS['ip']; |
|
| 253 | 253 | } |
| 254 | - $debug = ' /* ' . mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)) . ' */'; |
|
| 254 | + $debug = ' /* '.mysqli_real_escape_string($link, str_replace('*/', '@/', $debug)).' */'; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - $r = mysqli_query($link, $query . $debug); |
|
| 257 | + $r = mysqli_query($link, $query.$debug); |
|
| 258 | 258 | |
| 259 | 259 | //Eviter de propager le GoneAway sur les autres requetes d'un même processus PHP |
| 260 | 260 | if ($e = spip_mysql_errno($serveur)) { // Log d'un Gone Away |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
| 268 | 268 | $link = $connexion['link']; |
| 269 | 269 | //On retente au cas où |
| 270 | - $r = mysqli_query($link, $query . $debug); |
|
| 270 | + $r = mysqli_query($link, $query.$debug); |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | // d'utiliser ceux-ci, copie-colle de phpmyadmin |
| 296 | 296 | $query = preg_replace(",^TABLE\s*`([^`]*)`,i", "TABLE \\1", $query); |
| 297 | 297 | |
| 298 | - return spip_mysql_query("ALTER " . $query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 298 | + return spip_mysql_query("ALTER ".$query, $serveur, $requeter); # i.e. que PG se debrouille |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | * @return bool Toujours true |
| 309 | 309 | */ |
| 310 | 310 | function spip_mysql_optimize($table, $serveur = '', $requeter = true) { |
| 311 | - spip_mysql_query("OPTIMIZE TABLE " . $table); |
|
| 311 | + spip_mysql_query("OPTIMIZE TABLE ".$table); |
|
| 312 | 312 | |
| 313 | 313 | return true; |
| 314 | 314 | } |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | $link = $connexion['link']; |
| 332 | 332 | $db = $connexion['db']; |
| 333 | 333 | |
| 334 | - $query = 'EXPLAIN ' . _mysql_traite_query($query, $db, $prefixe); |
|
| 334 | + $query = 'EXPLAIN '._mysql_traite_query($query, $db, $prefixe); |
|
| 335 | 335 | $r = mysqli_query($link, $query); |
| 336 | 336 | |
| 337 | 337 | return spip_mysql_fetch($r, null, $serveur); |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | . calculer_mysql_expression('WHERE', $where) |
| 383 | 383 | . calculer_mysql_expression('GROUP BY', $groupby, ',') |
| 384 | 384 | . calculer_mysql_expression('HAVING', $having) |
| 385 | - . ($orderby ? ("\nORDER BY " . spip_mysql_order($orderby)) : '') |
|
| 385 | + . ($orderby ? ("\nORDER BY ".spip_mysql_order($orderby)) : '') |
|
| 386 | 386 | . ($limit ? "\nLIMIT $limit" : ''); |
| 387 | 387 | |
| 388 | 388 | // renvoyer la requete inerte si demandee |
@@ -472,12 +472,12 @@ discard block |
||
| 472 | 472 | $exp = "\n$expression "; |
| 473 | 473 | |
| 474 | 474 | if (!is_array($v)) { |
| 475 | - return $exp . $v; |
|
| 475 | + return $exp.$v; |
|
| 476 | 476 | } else { |
| 477 | 477 | if (strtoupper($join) === 'AND') { |
| 478 | - return $exp . join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 478 | + return $exp.join("\n\t$join ", array_map('calculer_mysql_where', $v)); |
|
| 479 | 479 | } else { |
| 480 | - return $exp . join($join, $v); |
|
| 480 | + return $exp.join($join, $v); |
|
| 481 | 481 | } |
| 482 | 482 | } |
| 483 | 483 | } |
@@ -495,17 +495,17 @@ discard block |
||
| 495 | 495 | if (substr($k, -1) == '@') { |
| 496 | 496 | // c'est une jointure qui se refere au from precedent |
| 497 | 497 | // pas de virgule |
| 498 | - $res .= ' ' . $v; |
|
| 498 | + $res .= ' '.$v; |
|
| 499 | 499 | } else { |
| 500 | 500 | if (!is_numeric($k)) { |
| 501 | 501 | $p = strpos($v, " "); |
| 502 | 502 | if ($p) { |
| 503 | - $v = substr($v, 0, $p) . " AS `$k`" . substr($v, $p); |
|
| 503 | + $v = substr($v, 0, $p)." AS `$k`".substr($v, $p); |
|
| 504 | 504 | } else { |
| 505 | 505 | $v .= " AS `$k`"; |
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | - $res .= ', ' . $v; |
|
| 508 | + $res .= ', '.$v; |
|
| 509 | 509 | } |
| 510 | 510 | } |
| 511 | 511 | |
@@ -534,13 +534,13 @@ discard block |
||
| 534 | 534 | function _mysql_traite_query($query, $db = '', $prefixe = '') { |
| 535 | 535 | |
| 536 | 536 | if ($GLOBALS['mysql_rappel_nom_base'] and $db) { |
| 537 | - $pref = '`' . $db . '`.'; |
|
| 537 | + $pref = '`'.$db.'`.'; |
|
| 538 | 538 | } else { |
| 539 | 539 | $pref = ''; |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | if ($prefixe) { |
| 543 | - $pref .= $prefixe . "_"; |
|
| 543 | + $pref .= $prefixe."_"; |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | if (!preg_match('/\s(SET|VALUES|WHERE|DATABASE)\s/i', $query, $regs)) { |
@@ -554,12 +554,12 @@ discard block |
||
| 554 | 554 | if (stripos($suite, "SELECT") !== false) { |
| 555 | 555 | list($suite, $textes) = query_echappe_textes($suite); |
| 556 | 556 | if (preg_match('/^(.*?)([(]\s*SELECT\b.*)$/si', $suite, $r)) { |
| 557 | - $suite = $r[1] . _mysql_traite_query($r[2], $db, $prefixe); |
|
| 557 | + $suite = $r[1]._mysql_traite_query($r[2], $db, $prefixe); |
|
| 558 | 558 | } |
| 559 | 559 | $suite = query_reinjecte_textes($suite, $textes); |
| 560 | 560 | } |
| 561 | 561 | } |
| 562 | - $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1' . $pref, $query) . $suite; |
|
| 562 | + $r = preg_replace(_SQL_PREFIXE_TABLE_MYSQL, '\1'.$pref, $query).$suite; |
|
| 563 | 563 | |
| 564 | 564 | // en option, remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
| 565 | 565 | // remplacer les emoji (que mysql ne sait pas gérer) en 💩 |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | $link = _mysql_link($serveur); |
| 594 | 594 | $ok = mysqli_select_db($link, $db); |
| 595 | 595 | if (!$ok) { |
| 596 | - spip_log('Echec mysqli_selectdb. Erreur : ' . mysqli_error($link), 'mysql.' . _LOG_CRITIQUE); |
|
| 596 | + spip_log('Echec mysqli_selectdb. Erreur : '.mysqli_error($link), 'mysql.'._LOG_CRITIQUE); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | return $ok; |
@@ -683,10 +683,10 @@ discard block |
||
| 683 | 683 | |
| 684 | 684 | $character_set = ""; |
| 685 | 685 | if (@$GLOBALS['meta']['charset_sql_base']) { |
| 686 | - $character_set .= " CHARACTER SET " . $GLOBALS['meta']['charset_sql_base']; |
|
| 686 | + $character_set .= " CHARACTER SET ".$GLOBALS['meta']['charset_sql_base']; |
|
| 687 | 687 | } |
| 688 | 688 | if (@$GLOBALS['meta']['charset_collation_sql_base']) { |
| 689 | - $character_set .= " COLLATE " . $GLOBALS['meta']['charset_collation_sql_base']; |
|
| 689 | + $character_set .= " COLLATE ".$GLOBALS['meta']['charset_collation_sql_base']; |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | foreach ($champs as $k => $v) { |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | if (preg_match(',(char|text),i', $defs[1]) |
| 696 | 696 | and !preg_match(',(binary|CHARACTER|COLLATE),i', $v) |
| 697 | 697 | ) { |
| 698 | - $v = $defs[1] . $character_set . ' ' . substr($v, strlen($defs[1])); |
|
| 698 | + $v = $defs[1].$character_set.' '.substr($v, strlen($defs[1])); |
|
| 699 | 699 | } |
| 700 | 700 | } |
| 701 | 701 | |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | $s = ","; |
| 708 | 708 | } |
| 709 | 709 | $temporary = $temporary ? 'TEMPORARY' : ''; |
| 710 | - $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query" . ($keys ? ",$keys" : '') . ")" |
|
| 710 | + $q = "CREATE $temporary TABLE IF NOT EXISTS $nom ($query".($keys ? ",$keys" : '').")" |
|
| 711 | 711 | . " ENGINE=MyISAM" |
| 712 | 712 | . ($character_set ? " DEFAULT $character_set" : "") |
| 713 | 713 | . "\n"; |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | return false; |
| 788 | 788 | } |
| 789 | 789 | |
| 790 | - $query = "CREATE VIEW $nom AS " . $query_select; |
|
| 790 | + $query = "CREATE VIEW $nom AS ".$query_select; |
|
| 791 | 791 | |
| 792 | 792 | return spip_mysql_query($query, $serveur, $requeter); |
| 793 | 793 | } |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | * Ressource à utiliser avec sql_fetch() |
| 846 | 846 | **/ |
| 847 | 847 | function spip_mysql_showbase($match, $serveur = '', $requeter = true) { |
| 848 | - return spip_mysql_query("SHOW TABLES LIKE " . _q($match), $serveur, $requeter); |
|
| 848 | + return spip_mysql_query("SHOW TABLES LIKE "._q($match), $serveur, $requeter); |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | /** |
@@ -939,22 +939,22 @@ discard block |
||
| 939 | 939 | } |
| 940 | 940 | if ($val['Default'] === '0' || $val['Default']) { |
| 941 | 941 | if (preg_match('/[A-Z_]/', $val['Default'])) { |
| 942 | - $nfields[$val["Field"]] .= ' DEFAULT ' . $val['Default']; |
|
| 942 | + $nfields[$val["Field"]] .= ' DEFAULT '.$val['Default']; |
|
| 943 | 943 | } else { |
| 944 | - $nfields[$val["Field"]] .= " DEFAULT '" . $val['Default'] . "'"; |
|
| 944 | + $nfields[$val["Field"]] .= " DEFAULT '".$val['Default']."'"; |
|
| 945 | 945 | } |
| 946 | 946 | } |
| 947 | 947 | if ($val['Extra']) { |
| 948 | - $nfields[$val["Field"]] .= ' ' . $val['Extra']; |
|
| 948 | + $nfields[$val["Field"]] .= ' '.$val['Extra']; |
|
| 949 | 949 | } |
| 950 | 950 | if ($val['Key'] == 'PRI') { |
| 951 | 951 | $nkeys['PRIMARY KEY'] = $val["Field"]; |
| 952 | 952 | } else { |
| 953 | 953 | if ($val['Key'] == 'MUL') { |
| 954 | - $nkeys['KEY ' . $val["Field"]] = $val["Field"]; |
|
| 954 | + $nkeys['KEY '.$val["Field"]] = $val["Field"]; |
|
| 955 | 955 | } else { |
| 956 | 956 | if ($val['Key'] == 'UNI') { |
| 957 | - $nkeys['UNIQUE KEY ' . $val["Field"]] = $val["Field"]; |
|
| 957 | + $nkeys['UNIQUE KEY '.$val["Field"]] = $val["Field"]; |
|
| 958 | 958 | } |
| 959 | 959 | } |
| 960 | 960 | } |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | $serveur = '', |
| 1026 | 1026 | $requeter = true |
| 1027 | 1027 | ) { |
| 1028 | - $c = !$groupby ? '*' : ('DISTINCT ' . (is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1028 | + $c = !$groupby ? '*' : ('DISTINCT '.(is_string($groupby) ? $groupby : join(',', $groupby))); |
|
| 1029 | 1029 | |
| 1030 | 1030 | $r = spip_mysql_select("COUNT($c)", $from, $where, '', '', '', $having, $serveur, $requeter); |
| 1031 | 1031 | if (!$requeter) { |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | if ($s) { |
| 1066 | 1066 | $trace = debug_backtrace(); |
| 1067 | 1067 | if ($trace[0]['function'] != "spip_mysql_error") { |
| 1068 | - spip_log("$s - $query - " . sql_error_backtrace(), 'mysql.' . _LOG_ERREUR); |
|
| 1068 | + spip_log("$s - $query - ".sql_error_backtrace(), 'mysql.'._LOG_ERREUR); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | } |
| 1071 | 1071 | |
@@ -1232,7 +1232,7 @@ discard block |
||
| 1232 | 1232 | $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | - return spip_mysql_insert($table, "(" . join(',', array_keys($couples)) . ")", "(" . join(',', $couples) . ")", $desc, |
|
| 1235 | + return spip_mysql_insert($table, "(".join(',', array_keys($couples)).")", "(".join(',', $couples).")", $desc, |
|
| 1236 | 1236 | $serveur, $requeter); |
| 1237 | 1237 | } |
| 1238 | 1238 | |
@@ -1266,7 +1266,7 @@ discard block |
||
| 1266 | 1266 | } |
| 1267 | 1267 | $fields = isset($desc['field']) ? $desc['field'] : array(); |
| 1268 | 1268 | |
| 1269 | - $cles = "(" . join(',', array_keys(reset($tab_couples))) . ')'; |
|
| 1269 | + $cles = "(".join(',', array_keys(reset($tab_couples))).')'; |
|
| 1270 | 1270 | $valeurs = array(); |
| 1271 | 1271 | $r = false; |
| 1272 | 1272 | |
@@ -1275,7 +1275,7 @@ discard block |
||
| 1275 | 1275 | foreach ($couples as $champ => $val) { |
| 1276 | 1276 | $couples[$champ] = spip_mysql_cite($val, $fields[$champ]); |
| 1277 | 1277 | } |
| 1278 | - $valeurs[] = '(' . join(',', $couples) . ')'; |
|
| 1278 | + $valeurs[] = '('.join(',', $couples).')'; |
|
| 1279 | 1279 | if (count($valeurs) >= 100) { |
| 1280 | 1280 | $r = spip_mysql_insert($table, $cles, join(', ', $valeurs), $desc, $serveur, $requeter); |
| 1281 | 1281 | $valeurs = array(); |
@@ -1312,7 +1312,7 @@ discard block |
||
| 1312 | 1312 | function spip_mysql_update($table, $champs, $where = '', $desc = array(), $serveur = '', $requeter = true) { |
| 1313 | 1313 | $set = array(); |
| 1314 | 1314 | foreach ($champs as $champ => $val) { |
| 1315 | - $set[] = $champ . "=$val"; |
|
| 1315 | + $set[] = $champ."=$val"; |
|
| 1316 | 1316 | } |
| 1317 | 1317 | if (!empty($set)) { |
| 1318 | 1318 | return spip_mysql_query( |
@@ -1366,7 +1366,7 @@ discard block |
||
| 1366 | 1366 | } |
| 1367 | 1367 | $set = array(); |
| 1368 | 1368 | foreach ($champs as $champ => $val) { |
| 1369 | - $set[] = $champ . '=' . spip_mysql_cite($val, @$fields[$champ]); |
|
| 1369 | + $set[] = $champ.'='.spip_mysql_cite($val, @$fields[$champ]); |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | 1372 | return spip_mysql_query( |
@@ -1431,8 +1431,8 @@ discard block |
||
| 1431 | 1431 | * - False en cas d'erreur. |
| 1432 | 1432 | **/ |
| 1433 | 1433 | function spip_mysql_replace($table, $couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1434 | - return spip_mysql_query("REPLACE $table (" . join(',', array_keys($couples)) . ') VALUES (' . join(',', |
|
| 1435 | - array_map('_q', $couples)) . ')', $serveur, $requeter); |
|
| 1434 | + return spip_mysql_query("REPLACE $table (".join(',', array_keys($couples)).') VALUES ('.join(',', |
|
| 1435 | + array_map('_q', $couples)).')', $serveur, $requeter); |
|
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | |
@@ -1461,10 +1461,10 @@ discard block |
||
| 1461 | 1461 | * - False en cas d'erreur. |
| 1462 | 1462 | **/ |
| 1463 | 1463 | function spip_mysql_replace_multi($table, $tab_couples, $desc = array(), $serveur = '', $requeter = true) { |
| 1464 | - $cles = "(" . join(',', array_keys($tab_couples[0])) . ')'; |
|
| 1464 | + $cles = "(".join(',', array_keys($tab_couples[0])).')'; |
|
| 1465 | 1465 | $valeurs = array(); |
| 1466 | 1466 | foreach ($tab_couples as $couples) { |
| 1467 | - $valeurs[] = '(' . join(',', array_map('_q', $couples)) . ')'; |
|
| 1467 | + $valeurs[] = '('.join(',', array_map('_q', $couples)).')'; |
|
| 1468 | 1468 | } |
| 1469 | 1469 | $valeurs = implode(', ', $valeurs); |
| 1470 | 1470 | |
@@ -1484,28 +1484,28 @@ discard block |
||
| 1484 | 1484 | */ |
| 1485 | 1485 | function spip_mysql_multi($objet, $lang) { |
| 1486 | 1486 | $lengthlang = strlen("[$lang]"); |
| 1487 | - $posmulti = "INSTR(" . $objet . ", '<multi>')"; |
|
| 1488 | - $posfinmulti = "INSTR(" . $objet . ", '</multi>')"; |
|
| 1489 | - $debutchaine = "LEFT(" . $objet . ", $posmulti-1)"; |
|
| 1490 | - $finchaine = "RIGHT(" . $objet . ", CHAR_LENGTH(" . $objet . ") -(7+$posfinmulti))"; |
|
| 1491 | - $chainemulti = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1492 | - $poslang = "INSTR($chainemulti,'[" . $lang . "]')"; |
|
| 1487 | + $posmulti = "INSTR(".$objet.", '<multi>')"; |
|
| 1488 | + $posfinmulti = "INSTR(".$objet.", '</multi>')"; |
|
| 1489 | + $debutchaine = "LEFT(".$objet.", $posmulti-1)"; |
|
| 1490 | + $finchaine = "RIGHT(".$objet.", CHAR_LENGTH(".$objet.") -(7+$posfinmulti))"; |
|
| 1491 | + $chainemulti = "TRIM(SUBSTRING(".$objet.", $posmulti+7, $posfinmulti -(7+$posmulti)))"; |
|
| 1492 | + $poslang = "INSTR($chainemulti,'[".$lang."]')"; |
|
| 1493 | 1493 | $poslang = "IF($poslang=0,INSTR($chainemulti,']')+1,$poslang+$lengthlang)"; |
| 1494 | - $chainelang = "TRIM(SUBSTRING(" . $objet . ", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1495 | - $posfinlang = "INSTR(" . $chainelang . ", '[')"; |
|
| 1494 | + $chainelang = "TRIM(SUBSTRING(".$objet.", $posmulti+7+$poslang-1,$posfinmulti -($posmulti+7+$poslang-1) ))"; |
|
| 1495 | + $posfinlang = "INSTR(".$chainelang.", '[')"; |
|
| 1496 | 1496 | $chainelang = "IF($posfinlang>0,LEFT($chainelang,$posfinlang-1),$chainelang)"; |
| 1497 | 1497 | //$chainelang = "LEFT($chainelang,$posfinlang-1)"; |
| 1498 | - $retour = "(TRIM(IF($posmulti = 0 , " . |
|
| 1499 | - " TRIM(" . $objet . "), " . |
|
| 1500 | - " CONCAT( " . |
|
| 1501 | - " $debutchaine, " . |
|
| 1502 | - " IF( " . |
|
| 1503 | - " $poslang = 0, " . |
|
| 1504 | - " $chainemulti, " . |
|
| 1505 | - " $chainelang" . |
|
| 1506 | - " ), " . |
|
| 1507 | - " $finchaine" . |
|
| 1508 | - " ) " . |
|
| 1498 | + $retour = "(TRIM(IF($posmulti = 0 , ". |
|
| 1499 | + " TRIM(".$objet."), ". |
|
| 1500 | + " CONCAT( ". |
|
| 1501 | + " $debutchaine, ". |
|
| 1502 | + " IF( ". |
|
| 1503 | + " $poslang = 0, ". |
|
| 1504 | + " $chainemulti, ". |
|
| 1505 | + " $chainelang". |
|
| 1506 | + " ), ". |
|
| 1507 | + " $finchaine". |
|
| 1508 | + " ) ". |
|
| 1509 | 1509 | "))) AS multi"; |
| 1510 | 1510 | |
| 1511 | 1511 | return $retour; |
@@ -1522,7 +1522,7 @@ discard block |
||
| 1522 | 1522 | * Valeur hexadécimale pour MySQL |
| 1523 | 1523 | **/ |
| 1524 | 1524 | function spip_mysql_hex($v) { |
| 1525 | - return "0x" . $v; |
|
| 1525 | + return "0x".$v; |
|
| 1526 | 1526 | } |
| 1527 | 1527 | |
| 1528 | 1528 | /** |
@@ -1562,7 +1562,7 @@ discard block |
||
| 1562 | 1562 | * Expression SQL |
| 1563 | 1563 | **/ |
| 1564 | 1564 | function spip_mysql_date_proche($champ, $interval, $unite) { |
| 1565 | - $use_now = ( ($champ === 'maj' or strpos($champ, '.maj')) ? true : false ); |
|
| 1565 | + $use_now = (($champ === 'maj' or strpos($champ, '.maj')) ? true : false); |
|
| 1566 | 1566 | return '(' |
| 1567 | 1567 | . $champ |
| 1568 | 1568 | . (($interval <= 0) ? '>' : '<') |
@@ -1616,7 +1616,7 @@ discard block |
||
| 1616 | 1616 | elseif (is_numeric($v)) { |
| 1617 | 1617 | return strval($v); |
| 1618 | 1618 | } |
| 1619 | - return "'" . addslashes($v) . "'"; |
|
| 1619 | + return "'".addslashes($v)."'"; |
|
| 1620 | 1620 | } |
| 1621 | 1621 | |
| 1622 | 1622 | if (is_null($v) |
@@ -1638,7 +1638,7 @@ discard block |
||
| 1638 | 1638 | } |
| 1639 | 1639 | } |
| 1640 | 1640 | |
| 1641 | - return ("'" . addslashes($v) . "'"); |
|
| 1641 | + return ("'".addslashes($v)."'"); |
|
| 1642 | 1642 | } |
| 1643 | 1643 | |
| 1644 | 1644 | |
@@ -1667,9 +1667,9 @@ discard block |
||
| 1667 | 1667 | $connexion = &$GLOBALS['connexions'][0]; |
| 1668 | 1668 | $bd = $connexion['db']; |
| 1669 | 1669 | $prefixe = $connexion['prefixe']; |
| 1670 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1670 | + $nom = "$bd:$prefixe:$nom"._LOCK_TIME; |
|
| 1671 | 1671 | |
| 1672 | - $connexion['last'] = $q = "SELECT GET_LOCK(" . _q($nom) . ", $timeout) AS n"; |
|
| 1672 | + $connexion['last'] = $q = "SELECT GET_LOCK("._q($nom).", $timeout) AS n"; |
|
| 1673 | 1673 | |
| 1674 | 1674 | $q = @sql_fetch(mysqli_query(_mysql_link(), $q)); |
| 1675 | 1675 | if (!$q) { |
@@ -1696,9 +1696,9 @@ discard block |
||
| 1696 | 1696 | $connexion = &$GLOBALS['connexions'][0]; |
| 1697 | 1697 | $bd = $connexion['db']; |
| 1698 | 1698 | $prefixe = $connexion['prefixe']; |
| 1699 | - $nom = "$bd:$prefixe:$nom" . _LOCK_TIME; |
|
| 1699 | + $nom = "$bd:$prefixe:$nom"._LOCK_TIME; |
|
| 1700 | 1700 | |
| 1701 | - $connexion['last'] = $q = "SELECT RELEASE_LOCK(" . _q($nom) . ")"; |
|
| 1701 | + $connexion['last'] = $q = "SELECT RELEASE_LOCK("._q($nom).")"; |
|
| 1702 | 1702 | mysqli_query(_mysql_link(), $q); |
| 1703 | 1703 | } |
| 1704 | 1704 | |
@@ -1734,7 +1734,7 @@ discard block |
||
| 1734 | 1734 | } else { |
| 1735 | 1735 | $GLOBALS['mysql_rappel_nom_base'] = false; |
| 1736 | 1736 | |
| 1737 | - return "\$GLOBALS['mysql_rappel_nom_base'] = false; " . |
|
| 1737 | + return "\$GLOBALS['mysql_rappel_nom_base'] = false; ". |
|
| 1738 | 1738 | "/* echec de test_rappel_nom_base_mysql a l'installation. */\n"; |
| 1739 | 1739 | } |
| 1740 | 1740 | } |
@@ -50,11 +50,9 @@ discard block |
||
| 50 | 50 | $port and !is_numeric($socket = $port) |
| 51 | 51 | and (!$host or $host=='localhost')) { |
| 52 | 52 | $link = @mysqli_connect($host, $login, $pass, '', null, $socket); |
| 53 | - } |
|
| 54 | - elseif ($port) { |
|
| 53 | + } elseif ($port) { |
|
| 55 | 54 | $link = @mysqli_connect($host, $login, $pass, '', $port); |
| 56 | - } |
|
| 57 | - else { |
|
| 55 | + } else { |
|
| 58 | 56 | $link = @mysqli_connect($host, $login, $pass); |
| 59 | 57 | } |
| 60 | 58 | |
@@ -1612,8 +1610,7 @@ discard block |
||
| 1612 | 1610 | if (!$type) { |
| 1613 | 1611 | if (is_bool($v)) { |
| 1614 | 1612 | return strval(intval($v)); |
| 1615 | - } |
|
| 1616 | - elseif (is_numeric($v)) { |
|
| 1613 | + } elseif (is_numeric($v)) { |
|
| 1617 | 1614 | return strval($v); |
| 1618 | 1615 | } |
| 1619 | 1616 | return "'" . addslashes($v) . "'"; |
@@ -319,7 +319,7 @@ |
||
| 319 | 319 | /** |
| 320 | 320 | * Constructeur |
| 321 | 321 | * |
| 322 | - * @param array $process ? |
|
| 322 | + * @param boolean $process ? |
|
| 323 | 323 | **/ |
| 324 | 324 | public function __construct($process = array()) { |
| 325 | 325 | if (is_array($process)) { |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -23,333 +23,333 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | class ValidateurXML { |
| 25 | 25 | |
| 26 | - // https://code.spip.net/@validerElement |
|
| 27 | - public function validerElement($phraseur, $name, $attrs) { |
|
| 28 | - if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 29 | - if ($p = strpos($name, ':')) { |
|
| 30 | - $name = substr($name, $p + 1); |
|
| 31 | - $p = isset($this->dtc->elements[$name]); |
|
| 32 | - } |
|
| 33 | - if (!$p) { |
|
| 34 | - coordonnees_erreur($this, " <b>$name</b> : " |
|
| 35 | - . _T('zxml_inconnu_balise')); |
|
| 36 | - |
|
| 37 | - return; |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - // controler les filles illegitimes, ca suffit |
|
| 41 | - $depth = $this->depth; |
|
| 42 | - $ouvrant = $this->ouvrant; |
|
| 43 | - #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 44 | - if (isset($ouvrant[$depth])) { |
|
| 45 | - if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 46 | - $pere = $r[1]; |
|
| 47 | - #spip_log("pere $pere"); |
|
| 48 | - if (isset($this->dtc->elements[$pere])) { |
|
| 49 | - $fils = $this->dtc->elements[$pere]; |
|
| 50 | - #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 51 | - if (!($p = @in_array($name, $fils))) { |
|
| 52 | - if ($p = strpos($name, ':')) { |
|
| 53 | - $p = substr($name, $p + 1); |
|
| 54 | - $p = @in_array($p, $fils); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - if (!$p) { |
|
| 58 | - $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 59 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 60 | - . _T('zxml_non_fils') |
|
| 61 | - . ' <b>' |
|
| 62 | - . $pere |
|
| 63 | - . '</b>' |
|
| 64 | - . (!$bons_peres ? '' |
|
| 65 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 66 | - } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 67 | - $frat = substr($depth, 2); |
|
| 68 | - if (!isset($this->fratrie[$frat])) { |
|
| 69 | - $this->fratrie[$frat] = ''; |
|
| 70 | - } |
|
| 71 | - $this->fratrie[$frat] .= "$name "; |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - // Init de la suite des balises a memoriser si regle difficile |
|
| 77 | - if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 78 | - $this->fratrie[$depth] = ''; |
|
| 79 | - } |
|
| 80 | - if (isset($this->dtc->attributs[$name])) { |
|
| 81 | - foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 82 | - if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 83 | - coordonnees_erreur($this, " <b>$n</b>" |
|
| 84 | - . ' : ' |
|
| 85 | - . _T('zxml_obligatoire_attribut') |
|
| 86 | - . " <b>$name</b>"); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // https://code.spip.net/@validerAttribut |
|
| 93 | - public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 94 | - // Si la balise est inconnue, eviter d'insister |
|
| 95 | - if (!isset($this->dtc->attributs[$bal])) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $a = $this->dtc->attributs[$bal]; |
|
| 100 | - if (!isset($a[$name])) { |
|
| 101 | - $bons = join(', ', array_keys($a)); |
|
| 102 | - if ($bons) { |
|
| 103 | - $bons = " title=' " . |
|
| 104 | - _T('zxml_connus_attributs') . |
|
| 105 | - ' : ' . |
|
| 106 | - $bons . |
|
| 107 | - "'"; |
|
| 108 | - } |
|
| 109 | - $bons .= " style='font-weight: bold'"; |
|
| 110 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 111 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 112 | - . " <a$bons>$bal</a> (" |
|
| 113 | - . _T('zxml_survoler') |
|
| 114 | - . ")"); |
|
| 115 | - } else { |
|
| 116 | - $type = $a[$name][0]; |
|
| 117 | - if (!preg_match('/^\w+$/', $type)) { |
|
| 118 | - $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 119 | - } else { |
|
| 120 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 121 | - $this->$f($phraseur, $name, $val, $bal); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - # else spip_log("$type type d'attribut inconnu"); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 129 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 133 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // https://code.spip.net/@validerAttribut_ID |
|
| 137 | - public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 138 | - if (isset($this->ids[$val])) { |
|
| 139 | - list($l, $c) = $this->ids[$val]; |
|
| 140 | - coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 141 | - . _T('zxml_valeur_attribut') |
|
| 142 | - . " <b>$name</b> " |
|
| 143 | - . _T('zxml_de') |
|
| 144 | - . " <b>$bal</b> " |
|
| 145 | - . _T('zxml_vu') |
|
| 146 | - . " (L$l,C$c)"); |
|
| 147 | - } else { |
|
| 148 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 149 | - $this->ids[$val] = array(xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // https://code.spip.net/@validerAttribut_IDREF |
|
| 154 | - public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 155 | - $this->idrefs[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // https://code.spip.net/@validerAttribut_IDREFS |
|
| 159 | - public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 160 | - $this->idrefss[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // https://code.spip.net/@valider_motif |
|
| 164 | - public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 165 | - if (!preg_match($motif, $val)) { |
|
| 166 | - coordonnees_erreur($this, "<b>$val</b> " |
|
| 167 | - . _T('zxml_valeur_attribut') |
|
| 168 | - . " <b>$name</b> " |
|
| 169 | - . _T('zxml_de') |
|
| 170 | - . " <b>$bal</b> " |
|
| 171 | - . _T('zxml_non_conforme') |
|
| 172 | - . "</p><p>" |
|
| 173 | - . "<b>" . $motif . "</b>"); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - // https://code.spip.net/@valider_idref |
|
| 178 | - public function valider_idref($nom, $ligne, $col) { |
|
| 179 | - if (!isset($this->ids[$nom])) { |
|
| 180 | - $this->err[] = array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // https://code.spip.net/@valider_passe2 |
|
| 185 | - public function valider_passe2() { |
|
| 186 | - if (!$this->err) { |
|
| 187 | - foreach ($this->idrefs as $idref) { |
|
| 188 | - list($nom, $ligne, $col) = $idref; |
|
| 189 | - $this->valider_idref($nom, $ligne, $col); |
|
| 190 | - } |
|
| 191 | - foreach ($this->idrefss as $idref) { |
|
| 192 | - list($noms, $ligne, $col) = $idref; |
|
| 193 | - foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 194 | - $this->valider_idref($nom, $ligne, $col); |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // https://code.spip.net/@debutElement |
|
| 201 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 202 | - if ($this->dtc->elements) { |
|
| 203 | - $this->validerElement($phraseur, $name, $attrs); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($f = $this->process['debut']) { |
|
| 207 | - $f($this, $name, $attrs); |
|
| 208 | - } |
|
| 209 | - $depth = $this->depth; |
|
| 210 | - $this->debuts[$depth] = strlen($this->res); |
|
| 211 | - foreach ($attrs as $k => $v) { |
|
| 212 | - $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // https://code.spip.net/@finElement |
|
| 217 | - public function finElement($phraseur, $name) { |
|
| 218 | - $depth = $this->depth; |
|
| 219 | - $contenu = $this->contenu; |
|
| 220 | - |
|
| 221 | - $n = strlen($this->res); |
|
| 222 | - $c = strlen(trim($contenu[$depth])); |
|
| 223 | - $k = $this->debuts[$depth]; |
|
| 224 | - |
|
| 225 | - $regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false; |
|
| 226 | - $vide = ($regle == 'EMPTY'); |
|
| 227 | - // controler que les balises devant etre vides le sont |
|
| 228 | - if ($vide) { |
|
| 229 | - if ($n <> ($k + $c)) { |
|
| 230 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 231 | - } |
|
| 232 | - // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 233 | - } elseif ($regle and ($regle != '*')) { |
|
| 234 | - if ($regle == '+') { |
|
| 235 | - // iteration de disjonction non vide: 1 balise au - |
|
| 236 | - if ($n == $k) { |
|
| 237 | - coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 238 | - . _T('zxml_vide_balise')); |
|
| 239 | - } |
|
| 240 | - } else { |
|
| 241 | - $f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null; |
|
| 242 | - if (is_null($f) or !preg_match($regle, $f)) { |
|
| 243 | - coordonnees_erreur($this, |
|
| 244 | - " <p>\n<b>$name</b> " |
|
| 245 | - . _T('zxml_succession_fils_incorrecte') |
|
| 246 | - . ' : <b>' |
|
| 247 | - . $f |
|
| 248 | - . '</b>'); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - } |
|
| 253 | - if ($f = $this->process['fin']) { |
|
| 254 | - $f($this, $name, $vide); |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - // https://code.spip.net/@textElement |
|
| 259 | - public function textElement($phraseur, $data) { |
|
| 260 | - if (trim($data)) { |
|
| 261 | - $d = $this->depth; |
|
| 262 | - $d = $this->ouvrant[$d]; |
|
| 263 | - preg_match('/^\s*(\S+)/', $d, $m); |
|
| 264 | - if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 265 | - coordonnees_erreur($this, " <p><b>" . $m[1] . "</b> " |
|
| 266 | - . _T('zxml_nonvide_balise') // message a affiner |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - if ($f = $this->process['text']) { |
|
| 271 | - $f($this, $data); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - public function piElement($phraseur, $target, $data) { |
|
| 276 | - if ($f = $this->process['pi']) { |
|
| 277 | - $f($this, $target, $data); |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - // Denonciation des entitees XML inconnues |
|
| 282 | - // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 283 | - // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 284 | - // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 285 | - // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 286 | - // le source de la page laisse legitimement supposer. |
|
| 287 | - |
|
| 288 | - // https://code.spip.net/@defautElement |
|
| 289 | - public function defaultElement($phraseur, $data) { |
|
| 290 | - if (!preg_match('/^<!--/', $data) |
|
| 291 | - and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 292 | - ) { |
|
| 293 | - foreach ($r as $m) { |
|
| 294 | - list($t, $e) = $m; |
|
| 295 | - if (!isset($this->dtc->entites[$e])) { |
|
| 296 | - coordonnees_erreur($this, " <b>$e</b> " |
|
| 297 | - . _T('zxml_inconnu_entite') |
|
| 298 | - . ' ' |
|
| 299 | - ); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 304 | - $f($this, $data); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - // https://code.spip.net/@phraserTout |
|
| 309 | - public function phraserTout($phraseur, $data) { |
|
| 310 | - xml_parsestring($this, $data); |
|
| 311 | - |
|
| 312 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 313 | - $this->err[] = array('DOCTYPE ?', 0, 0); |
|
| 314 | - } else { |
|
| 315 | - $this->valider_passe2($this); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Constructeur |
|
| 321 | - * |
|
| 322 | - * @param array $process ? |
|
| 323 | - **/ |
|
| 324 | - public function __construct($process = array()) { |
|
| 325 | - if (is_array($process)) { |
|
| 326 | - $this->process = $process; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - public $ids = array(); |
|
| 331 | - public $idrefs = array(); |
|
| 332 | - public $idrefss = array(); |
|
| 333 | - public $debuts = array(); |
|
| 334 | - public $fratrie = array(); |
|
| 335 | - |
|
| 336 | - public $dtc = null; |
|
| 337 | - public $sax = null; |
|
| 338 | - public $depth = ""; |
|
| 339 | - public $entete = ''; |
|
| 340 | - public $page = ''; |
|
| 341 | - public $res = ""; |
|
| 342 | - public $err = array(); |
|
| 343 | - public $contenu = array(); |
|
| 344 | - public $ouvrant = array(); |
|
| 345 | - public $reperes = array(); |
|
| 346 | - public $process = array( |
|
| 347 | - 'debut' => 'xml_debutElement', |
|
| 348 | - 'fin' => 'xml_finElement', |
|
| 349 | - 'text' => 'xml_textElement', |
|
| 350 | - 'pi' => 'xml_piElement', |
|
| 351 | - 'default' => 'xml_defaultElement' |
|
| 352 | - ); |
|
| 26 | + // https://code.spip.net/@validerElement |
|
| 27 | + public function validerElement($phraseur, $name, $attrs) { |
|
| 28 | + if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 29 | + if ($p = strpos($name, ':')) { |
|
| 30 | + $name = substr($name, $p + 1); |
|
| 31 | + $p = isset($this->dtc->elements[$name]); |
|
| 32 | + } |
|
| 33 | + if (!$p) { |
|
| 34 | + coordonnees_erreur($this, " <b>$name</b> : " |
|
| 35 | + . _T('zxml_inconnu_balise')); |
|
| 36 | + |
|
| 37 | + return; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + // controler les filles illegitimes, ca suffit |
|
| 41 | + $depth = $this->depth; |
|
| 42 | + $ouvrant = $this->ouvrant; |
|
| 43 | + #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 44 | + if (isset($ouvrant[$depth])) { |
|
| 45 | + if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 46 | + $pere = $r[1]; |
|
| 47 | + #spip_log("pere $pere"); |
|
| 48 | + if (isset($this->dtc->elements[$pere])) { |
|
| 49 | + $fils = $this->dtc->elements[$pere]; |
|
| 50 | + #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 51 | + if (!($p = @in_array($name, $fils))) { |
|
| 52 | + if ($p = strpos($name, ':')) { |
|
| 53 | + $p = substr($name, $p + 1); |
|
| 54 | + $p = @in_array($p, $fils); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + if (!$p) { |
|
| 58 | + $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 59 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 60 | + . _T('zxml_non_fils') |
|
| 61 | + . ' <b>' |
|
| 62 | + . $pere |
|
| 63 | + . '</b>' |
|
| 64 | + . (!$bons_peres ? '' |
|
| 65 | + : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 66 | + } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 67 | + $frat = substr($depth, 2); |
|
| 68 | + if (!isset($this->fratrie[$frat])) { |
|
| 69 | + $this->fratrie[$frat] = ''; |
|
| 70 | + } |
|
| 71 | + $this->fratrie[$frat] .= "$name "; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + // Init de la suite des balises a memoriser si regle difficile |
|
| 77 | + if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 78 | + $this->fratrie[$depth] = ''; |
|
| 79 | + } |
|
| 80 | + if (isset($this->dtc->attributs[$name])) { |
|
| 81 | + foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 82 | + if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 83 | + coordonnees_erreur($this, " <b>$n</b>" |
|
| 84 | + . ' : ' |
|
| 85 | + . _T('zxml_obligatoire_attribut') |
|
| 86 | + . " <b>$name</b>"); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // https://code.spip.net/@validerAttribut |
|
| 93 | + public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 94 | + // Si la balise est inconnue, eviter d'insister |
|
| 95 | + if (!isset($this->dtc->attributs[$bal])) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $a = $this->dtc->attributs[$bal]; |
|
| 100 | + if (!isset($a[$name])) { |
|
| 101 | + $bons = join(', ', array_keys($a)); |
|
| 102 | + if ($bons) { |
|
| 103 | + $bons = " title=' " . |
|
| 104 | + _T('zxml_connus_attributs') . |
|
| 105 | + ' : ' . |
|
| 106 | + $bons . |
|
| 107 | + "'"; |
|
| 108 | + } |
|
| 109 | + $bons .= " style='font-weight: bold'"; |
|
| 110 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 111 | + . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 112 | + . " <a$bons>$bal</a> (" |
|
| 113 | + . _T('zxml_survoler') |
|
| 114 | + . ")"); |
|
| 115 | + } else { |
|
| 116 | + $type = $a[$name][0]; |
|
| 117 | + if (!preg_match('/^\w+$/', $type)) { |
|
| 118 | + $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 119 | + } else { |
|
| 120 | + if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 121 | + $this->$f($phraseur, $name, $val, $bal); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + # else spip_log("$type type d'attribut inconnu"); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 129 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 133 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // https://code.spip.net/@validerAttribut_ID |
|
| 137 | + public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 138 | + if (isset($this->ids[$val])) { |
|
| 139 | + list($l, $c) = $this->ids[$val]; |
|
| 140 | + coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 141 | + . _T('zxml_valeur_attribut') |
|
| 142 | + . " <b>$name</b> " |
|
| 143 | + . _T('zxml_de') |
|
| 144 | + . " <b>$bal</b> " |
|
| 145 | + . _T('zxml_vu') |
|
| 146 | + . " (L$l,C$c)"); |
|
| 147 | + } else { |
|
| 148 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 149 | + $this->ids[$val] = array(xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // https://code.spip.net/@validerAttribut_IDREF |
|
| 154 | + public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 155 | + $this->idrefs[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // https://code.spip.net/@validerAttribut_IDREFS |
|
| 159 | + public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 160 | + $this->idrefss[] = array($val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // https://code.spip.net/@valider_motif |
|
| 164 | + public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 165 | + if (!preg_match($motif, $val)) { |
|
| 166 | + coordonnees_erreur($this, "<b>$val</b> " |
|
| 167 | + . _T('zxml_valeur_attribut') |
|
| 168 | + . " <b>$name</b> " |
|
| 169 | + . _T('zxml_de') |
|
| 170 | + . " <b>$bal</b> " |
|
| 171 | + . _T('zxml_non_conforme') |
|
| 172 | + . "</p><p>" |
|
| 173 | + . "<b>" . $motif . "</b>"); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + // https://code.spip.net/@valider_idref |
|
| 178 | + public function valider_idref($nom, $ligne, $col) { |
|
| 179 | + if (!isset($this->ids[$nom])) { |
|
| 180 | + $this->err[] = array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // https://code.spip.net/@valider_passe2 |
|
| 185 | + public function valider_passe2() { |
|
| 186 | + if (!$this->err) { |
|
| 187 | + foreach ($this->idrefs as $idref) { |
|
| 188 | + list($nom, $ligne, $col) = $idref; |
|
| 189 | + $this->valider_idref($nom, $ligne, $col); |
|
| 190 | + } |
|
| 191 | + foreach ($this->idrefss as $idref) { |
|
| 192 | + list($noms, $ligne, $col) = $idref; |
|
| 193 | + foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 194 | + $this->valider_idref($nom, $ligne, $col); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // https://code.spip.net/@debutElement |
|
| 201 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 202 | + if ($this->dtc->elements) { |
|
| 203 | + $this->validerElement($phraseur, $name, $attrs); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($f = $this->process['debut']) { |
|
| 207 | + $f($this, $name, $attrs); |
|
| 208 | + } |
|
| 209 | + $depth = $this->depth; |
|
| 210 | + $this->debuts[$depth] = strlen($this->res); |
|
| 211 | + foreach ($attrs as $k => $v) { |
|
| 212 | + $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // https://code.spip.net/@finElement |
|
| 217 | + public function finElement($phraseur, $name) { |
|
| 218 | + $depth = $this->depth; |
|
| 219 | + $contenu = $this->contenu; |
|
| 220 | + |
|
| 221 | + $n = strlen($this->res); |
|
| 222 | + $c = strlen(trim($contenu[$depth])); |
|
| 223 | + $k = $this->debuts[$depth]; |
|
| 224 | + |
|
| 225 | + $regle = isset($this->dtc->regles[$name]) ? $this->dtc->regles[$name] : false; |
|
| 226 | + $vide = ($regle == 'EMPTY'); |
|
| 227 | + // controler que les balises devant etre vides le sont |
|
| 228 | + if ($vide) { |
|
| 229 | + if ($n <> ($k + $c)) { |
|
| 230 | + coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 231 | + } |
|
| 232 | + // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 233 | + } elseif ($regle and ($regle != '*')) { |
|
| 234 | + if ($regle == '+') { |
|
| 235 | + // iteration de disjonction non vide: 1 balise au - |
|
| 236 | + if ($n == $k) { |
|
| 237 | + coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 238 | + . _T('zxml_vide_balise')); |
|
| 239 | + } |
|
| 240 | + } else { |
|
| 241 | + $f = isset($this->fratrie[substr($depth, 2)]) ? $this->fratrie[substr($depth, 2)] : null; |
|
| 242 | + if (is_null($f) or !preg_match($regle, $f)) { |
|
| 243 | + coordonnees_erreur($this, |
|
| 244 | + " <p>\n<b>$name</b> " |
|
| 245 | + . _T('zxml_succession_fils_incorrecte') |
|
| 246 | + . ' : <b>' |
|
| 247 | + . $f |
|
| 248 | + . '</b>'); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + } |
|
| 253 | + if ($f = $this->process['fin']) { |
|
| 254 | + $f($this, $name, $vide); |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + // https://code.spip.net/@textElement |
|
| 259 | + public function textElement($phraseur, $data) { |
|
| 260 | + if (trim($data)) { |
|
| 261 | + $d = $this->depth; |
|
| 262 | + $d = $this->ouvrant[$d]; |
|
| 263 | + preg_match('/^\s*(\S+)/', $d, $m); |
|
| 264 | + if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 265 | + coordonnees_erreur($this, " <p><b>" . $m[1] . "</b> " |
|
| 266 | + . _T('zxml_nonvide_balise') // message a affiner |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + if ($f = $this->process['text']) { |
|
| 271 | + $f($this, $data); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + public function piElement($phraseur, $target, $data) { |
|
| 276 | + if ($f = $this->process['pi']) { |
|
| 277 | + $f($this, $target, $data); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + // Denonciation des entitees XML inconnues |
|
| 282 | + // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 283 | + // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 284 | + // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 285 | + // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 286 | + // le source de la page laisse legitimement supposer. |
|
| 287 | + |
|
| 288 | + // https://code.spip.net/@defautElement |
|
| 289 | + public function defaultElement($phraseur, $data) { |
|
| 290 | + if (!preg_match('/^<!--/', $data) |
|
| 291 | + and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 292 | + ) { |
|
| 293 | + foreach ($r as $m) { |
|
| 294 | + list($t, $e) = $m; |
|
| 295 | + if (!isset($this->dtc->entites[$e])) { |
|
| 296 | + coordonnees_erreur($this, " <b>$e</b> " |
|
| 297 | + . _T('zxml_inconnu_entite') |
|
| 298 | + . ' ' |
|
| 299 | + ); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 304 | + $f($this, $data); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + // https://code.spip.net/@phraserTout |
|
| 309 | + public function phraserTout($phraseur, $data) { |
|
| 310 | + xml_parsestring($this, $data); |
|
| 311 | + |
|
| 312 | + if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 313 | + $this->err[] = array('DOCTYPE ?', 0, 0); |
|
| 314 | + } else { |
|
| 315 | + $this->valider_passe2($this); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Constructeur |
|
| 321 | + * |
|
| 322 | + * @param array $process ? |
|
| 323 | + **/ |
|
| 324 | + public function __construct($process = array()) { |
|
| 325 | + if (is_array($process)) { |
|
| 326 | + $this->process = $process; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + public $ids = array(); |
|
| 331 | + public $idrefs = array(); |
|
| 332 | + public $idrefss = array(); |
|
| 333 | + public $debuts = array(); |
|
| 334 | + public $fratrie = array(); |
|
| 335 | + |
|
| 336 | + public $dtc = null; |
|
| 337 | + public $sax = null; |
|
| 338 | + public $depth = ""; |
|
| 339 | + public $entete = ''; |
|
| 340 | + public $page = ''; |
|
| 341 | + public $res = ""; |
|
| 342 | + public $err = array(); |
|
| 343 | + public $contenu = array(); |
|
| 344 | + public $ouvrant = array(); |
|
| 345 | + public $reperes = array(); |
|
| 346 | + public $process = array( |
|
| 347 | + 'debut' => 'xml_debutElement', |
|
| 348 | + 'fin' => 'xml_finElement', |
|
| 349 | + 'text' => 'xml_textElement', |
|
| 350 | + 'pi' => 'xml_piElement', |
|
| 351 | + 'default' => 'xml_defaultElement' |
|
| 352 | + ); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | |
@@ -359,8 +359,8 @@ discard block |
||
| 359 | 359 | * |
| 360 | 360 | **/ |
| 361 | 361 | function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) { |
| 362 | - $f = new ValidateurXML($process); |
|
| 363 | - $sax = charger_fonction('sax', 'xml'); |
|
| 362 | + $f = new ValidateurXML($process); |
|
| 363 | + $sax = charger_fonction('sax', 'xml'); |
|
| 364 | 364 | |
| 365 | - return $sax($page, $apply, $f, $doctype, $charset); |
|
| 365 | + return $sax($page, $apply, $f, $doctype, $charset); |
|
| 366 | 366 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | . $pere |
| 63 | 63 | . '</b>' |
| 64 | 64 | . (!$bons_peres ? '' |
| 65 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 65 | + : ('<p style="font-size: 80%"> '._T('zxml_mais_de').' <b>'.$bons_peres.'</b></p>'))); |
|
| 66 | 66 | } elseif ($this->dtc->regles[$pere][0] == '/') { |
| 67 | 67 | $frat = substr($depth, 2); |
| 68 | 68 | if (!isset($this->fratrie[$frat])) { |
@@ -100,15 +100,15 @@ discard block |
||
| 100 | 100 | if (!isset($a[$name])) { |
| 101 | 101 | $bons = join(', ', array_keys($a)); |
| 102 | 102 | if ($bons) { |
| 103 | - $bons = " title=' " . |
|
| 104 | - _T('zxml_connus_attributs') . |
|
| 105 | - ' : ' . |
|
| 106 | - $bons . |
|
| 103 | + $bons = " title=' ". |
|
| 104 | + _T('zxml_connus_attributs'). |
|
| 105 | + ' : '. |
|
| 106 | + $bons. |
|
| 107 | 107 | "'"; |
| 108 | 108 | } |
| 109 | 109 | $bons .= " style='font-weight: bold'"; |
| 110 | 110 | coordonnees_erreur($this, " <b>$name</b> " |
| 111 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 111 | + . _T('zxml_inconnu_attribut').' '._T('zxml_de') |
|
| 112 | 112 | . " <a$bons>$bal</a> (" |
| 113 | 113 | . _T('zxml_survoler') |
| 114 | 114 | . ")"); |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | if (!preg_match('/^\w+$/', $type)) { |
| 118 | 118 | $this->valider_motif($phraseur, $name, $val, $bal, $type); |
| 119 | 119 | } else { |
| 120 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 120 | + if (method_exists($this, $f = 'validerAttribut_'.$type)) { |
|
| 121 | 121 | $this->$f($phraseur, $name, $val, $bal); |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -170,14 +170,14 @@ discard block |
||
| 170 | 170 | . " <b>$bal</b> " |
| 171 | 171 | . _T('zxml_non_conforme') |
| 172 | 172 | . "</p><p>" |
| 173 | - . "<b>" . $motif . "</b>"); |
|
| 173 | + . "<b>".$motif."</b>"); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | // https://code.spip.net/@valider_idref |
| 178 | 178 | public function valider_idref($nom, $ligne, $col) { |
| 179 | 179 | if (!isset($this->ids[$nom])) { |
| 180 | - $this->err[] = array(" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col); |
|
| 180 | + $this->err[] = array(" <p><b>$nom</b> "._T('zxml_inconnu_id'), $ligne, $col); |
|
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | // controler que les balises devant etre vides le sont |
| 228 | 228 | if ($vide) { |
| 229 | 229 | if ($n <> ($k + $c)) { |
| 230 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 230 | + coordonnees_erreur($this, " <p><b>$name</b> "._T('zxml_nonvide_balise')); |
|
| 231 | 231 | } |
| 232 | 232 | // pour les regles PCDATA ou iteration de disjonction, tout est fait |
| 233 | 233 | } elseif ($regle and ($regle != '*')) { |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | $d = $this->ouvrant[$d]; |
| 263 | 263 | preg_match('/^\s*(\S+)/', $d, $m); |
| 264 | 264 | if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
| 265 | - coordonnees_erreur($this, " <p><b>" . $m[1] . "</b> " |
|
| 265 | + coordonnees_erreur($this, " <p><b>".$m[1]."</b> " |
|
| 266 | 266 | . _T('zxml_nonvide_balise') // message a affiner |
| 267 | 267 | ); |
| 268 | 268 | } |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | public function phraserTout($phraseur, $data) { |
| 310 | 310 | xml_parsestring($this, $data); |
| 311 | 311 | |
| 312 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 312 | + if (!$this->dtc or preg_match(',^'._MESSAGE_DOCTYPE.',', $data)) { |
|
| 313 | 313 | $this->err[] = array('DOCTYPE ?', 0, 0); |
| 314 | 314 | } else { |
| 315 | 315 | $this->valider_passe2($this); |
@@ -457,6 +457,10 @@ |
||
| 457 | 457 | * aller a la position $n en parcourant |
| 458 | 458 | * un par un tous les elements |
| 459 | 459 | */ |
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * @param integer $n |
|
| 463 | + */ |
|
| 460 | 464 | private function seek_loop($n) { |
| 461 | 465 | if ($this->pos > $n) { |
| 462 | 466 | $this->rewind(); |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | // chercher la classe d'iterateur |
| 80 | 80 | // IterateurXXX |
| 81 | 81 | // definie dans le fichier iterateurs/xxx.php |
| 82 | - $class = "Iterateur" . $iterateur; |
|
| 82 | + $class = "Iterateur".$iterateur; |
|
| 83 | 83 | if (!class_exists($class)) { |
| 84 | - if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 84 | + if (!include_spip("iterateur/".strtolower($iterateur)) |
|
| 85 | 85 | or !class_exists($class) |
| 86 | 86 | ) { |
| 87 | 87 | die("Iterateur $iterateur non trouvé"); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | return $this->iter->$nom(); |
| 209 | 209 | } catch (Exception $e) { |
| 210 | 210 | // #GETCHILDREN sur un fichier de DirectoryIterator ... |
| 211 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 211 | + spip_log("Methode $nom en echec sur ".get_class($this->iter)); |
|
| 212 | 212 | spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
| 213 | 213 | |
| 214 | 214 | return ''; |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | |
| 291 | 291 | // Creer la fonction de filtrage sur $this |
| 292 | 292 | if ($this->filtre) { |
| 293 | - $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 294 | - $this->func_filtre = function () use ($filtres) { |
|
| 293 | + $filtres = 'return ('.join(') AND (', $this->filtre).');'; |
|
| 294 | + $this->func_filtre = function() use ($filtres) { |
|
| 295 | 295 | return eval($filtres); |
| 296 | 296 | }; |
| 297 | 297 | } |
@@ -313,28 +313,28 @@ discard block |
||
| 313 | 313 | # if (!in_array($cle, array('cle', 'valeur'))) |
| 314 | 314 | # return; |
| 315 | 315 | |
| 316 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 316 | + $a = '$this->get_select(\''.$cle.'\')'; |
|
| 317 | 317 | |
| 318 | 318 | $filtre = ''; |
| 319 | 319 | |
| 320 | 320 | if ($op == 'REGEXP') { |
| 321 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 321 | + $filtre = 'filtrer("match", '.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 322 | 322 | $op = ''; |
| 323 | 323 | } else { |
| 324 | 324 | if ($op == 'LIKE') { |
| 325 | 325 | $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
| 326 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 326 | + $filtre = 'filtrer("match", '.$a.', '.$valeur.')'; |
|
| 327 | 327 | $op = ''; |
| 328 | 328 | } else { |
| 329 | 329 | if ($op == '=') { |
| 330 | 330 | $op = '=='; |
| 331 | 331 | } else { |
| 332 | 332 | if ($op == 'IN') { |
| 333 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 333 | + $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 334 | 334 | $op = ''; |
| 335 | 335 | } else { |
| 336 | 336 | if (!in_array($op, array('<', '<=', '>', '>='))) { |
| 337 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 337 | + spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette |
|
| 338 | 338 | $op = ''; |
| 339 | 339 | } |
| 340 | 340 | } |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | if ($op) { |
| 346 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 346 | + $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | if ($not) { |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -22,578 +22,578 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | 24 | class IterFactory { |
| 25 | - public static function create($iterateur, $command, $info = null) { |
|
| 26 | - |
|
| 27 | - // cas des SI {si expression} analises tres tot |
|
| 28 | - // pour eviter le chargement de tout iterateur |
|
| 29 | - if (isset($command['si'])) { |
|
| 30 | - foreach ($command['si'] as $si) { |
|
| 31 | - if (!$si) { |
|
| 32 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | - return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | - // pour etre certain qu'on est sur un "php:") |
|
| 42 | - if (class_exists($iterateur)) { |
|
| 43 | - $a = isset($command['args']) ? $command['args'] : array(); |
|
| 44 | - |
|
| 45 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | - if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 48 | - $iter = $a[0]; |
|
| 49 | - |
|
| 50 | - // sinon, on cree un iterateur du type donne |
|
| 51 | - } else { |
|
| 52 | - // arguments de creation de l'iterateur... |
|
| 53 | - // (pas glop) |
|
| 54 | - try { |
|
| 55 | - switch (count($a)) { |
|
| 56 | - case 0: |
|
| 57 | - $iter = new $iterateur(); |
|
| 58 | - break; |
|
| 59 | - case 1: |
|
| 60 | - $iter = new $iterateur($a[0]); |
|
| 61 | - break; |
|
| 62 | - case 2: |
|
| 63 | - $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | - break; |
|
| 65 | - case 3: |
|
| 66 | - $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | - break; |
|
| 68 | - case 4: |
|
| 69 | - $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | - break; |
|
| 71 | - } |
|
| 72 | - } catch (Exception $e) { |
|
| 73 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | - spip_log($e->getMessage()); |
|
| 75 | - $iter = new EmptyIterator(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } else { |
|
| 79 | - // chercher la classe d'iterateur |
|
| 80 | - // IterateurXXX |
|
| 81 | - // definie dans le fichier iterateurs/xxx.php |
|
| 82 | - $class = "Iterateur" . $iterateur; |
|
| 83 | - if (!class_exists($class)) { |
|
| 84 | - if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 85 | - or !class_exists($class) |
|
| 86 | - ) { |
|
| 87 | - die("Iterateur $iterateur non trouvé"); |
|
| 88 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | - # $iter = new EmptyIterator(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - $iter = new $class($command, $info); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return new IterDecorator($iter, $command, $info); |
|
| 96 | - } |
|
| 25 | + public static function create($iterateur, $command, $info = null) { |
|
| 26 | + |
|
| 27 | + // cas des SI {si expression} analises tres tot |
|
| 28 | + // pour eviter le chargement de tout iterateur |
|
| 29 | + if (isset($command['si'])) { |
|
| 30 | + foreach ($command['si'] as $si) { |
|
| 31 | + if (!$si) { |
|
| 32 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | + return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | + // pour etre certain qu'on est sur un "php:") |
|
| 42 | + if (class_exists($iterateur)) { |
|
| 43 | + $a = isset($command['args']) ? $command['args'] : array(); |
|
| 44 | + |
|
| 45 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | + if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 48 | + $iter = $a[0]; |
|
| 49 | + |
|
| 50 | + // sinon, on cree un iterateur du type donne |
|
| 51 | + } else { |
|
| 52 | + // arguments de creation de l'iterateur... |
|
| 53 | + // (pas glop) |
|
| 54 | + try { |
|
| 55 | + switch (count($a)) { |
|
| 56 | + case 0: |
|
| 57 | + $iter = new $iterateur(); |
|
| 58 | + break; |
|
| 59 | + case 1: |
|
| 60 | + $iter = new $iterateur($a[0]); |
|
| 61 | + break; |
|
| 62 | + case 2: |
|
| 63 | + $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | + break; |
|
| 65 | + case 3: |
|
| 66 | + $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | + break; |
|
| 68 | + case 4: |
|
| 69 | + $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | + break; |
|
| 71 | + } |
|
| 72 | + } catch (Exception $e) { |
|
| 73 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | + spip_log($e->getMessage()); |
|
| 75 | + $iter = new EmptyIterator(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } else { |
|
| 79 | + // chercher la classe d'iterateur |
|
| 80 | + // IterateurXXX |
|
| 81 | + // definie dans le fichier iterateurs/xxx.php |
|
| 82 | + $class = "Iterateur" . $iterateur; |
|
| 83 | + if (!class_exists($class)) { |
|
| 84 | + if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 85 | + or !class_exists($class) |
|
| 86 | + ) { |
|
| 87 | + die("Iterateur $iterateur non trouvé"); |
|
| 88 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | + # $iter = new EmptyIterator(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + $iter = new $class($command, $info); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return new IterDecorator($iter, $command, $info); |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | class IterDecorator extends FilterIterator { |
| 101 | - private $iter; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Conditions de filtrage |
|
| 105 | - * ie criteres de selection |
|
| 106 | - * |
|
| 107 | - * @var array |
|
| 108 | - */ |
|
| 109 | - protected $filtre = array(); |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | - * |
|
| 114 | - * @var string |
|
| 115 | - */ |
|
| 116 | - protected $func_filtre = null; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Critere {offset, limit} |
|
| 120 | - * |
|
| 121 | - * @var int |
|
| 122 | - * @var int |
|
| 123 | - */ |
|
| 124 | - protected $offset = null; |
|
| 125 | - protected $limit = null; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * nombre d'elements recuperes depuis la position 0, |
|
| 129 | - * en tenant compte des filtres |
|
| 130 | - * |
|
| 131 | - * @var int |
|
| 132 | - */ |
|
| 133 | - protected $fetched = 0; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Y a t'il une erreur ? |
|
| 137 | - * |
|
| 138 | - * @var bool |
|
| 139 | - **/ |
|
| 140 | - protected $err = false; |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Drapeau a activer en cas d'echec |
|
| 144 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | - */ |
|
| 146 | - public function err() { |
|
| 147 | - if (method_exists($this->iter, 'err')) { |
|
| 148 | - return $this->iter->err(); |
|
| 149 | - } |
|
| 150 | - if (property_exists($this->iter, 'err')) { |
|
| 151 | - return $this->iter->err; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | - parent::__construct($iter); |
|
| 159 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | - |
|
| 161 | - // recuperer l'iterateur transmis |
|
| 162 | - $this->iter = $this->getInnerIterator(); |
|
| 163 | - $this->command = $command; |
|
| 164 | - $this->info = $info; |
|
| 165 | - $this->pos = 0; |
|
| 166 | - $this->fetched = 0; |
|
| 167 | - |
|
| 168 | - // chercher la liste des champs a retourner par |
|
| 169 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | - $this->calculer_select(); |
|
| 172 | - $this->calculer_filtres(); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | - if (isset($this->iter->err)) { |
|
| 177 | - $this->err = $this->iter->err; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | - //$this->total = $this->count(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - // calcule les elements a retournes par fetch() |
|
| 186 | - // enleve les elements inutiles du select() |
|
| 187 | - // |
|
| 188 | - private function calculer_select() { |
|
| 189 | - if ($select = &$this->command['select']) { |
|
| 190 | - foreach ($select as $s) { |
|
| 191 | - // /!\ $s = '.nom' |
|
| 192 | - if ($s[0] == '.') { |
|
| 193 | - $s = substr($s, 1); |
|
| 194 | - } |
|
| 195 | - $this->select[] = $s; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // recuperer la valeur d'une balise #X |
|
| 201 | - // en fonction des methodes |
|
| 202 | - // et proprietes disponibles |
|
| 203 | - public function get_select($nom) { |
|
| 204 | - if (is_object($this->iter) |
|
| 205 | - and method_exists($this->iter, $nom) |
|
| 206 | - ) { |
|
| 207 | - try { |
|
| 208 | - return $this->iter->$nom(); |
|
| 209 | - } catch (Exception $e) { |
|
| 210 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 211 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 213 | - |
|
| 214 | - return ''; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - /* |
|
| 101 | + private $iter; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Conditions de filtrage |
|
| 105 | + * ie criteres de selection |
|
| 106 | + * |
|
| 107 | + * @var array |
|
| 108 | + */ |
|
| 109 | + protected $filtre = array(); |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | + * |
|
| 114 | + * @var string |
|
| 115 | + */ |
|
| 116 | + protected $func_filtre = null; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Critere {offset, limit} |
|
| 120 | + * |
|
| 121 | + * @var int |
|
| 122 | + * @var int |
|
| 123 | + */ |
|
| 124 | + protected $offset = null; |
|
| 125 | + protected $limit = null; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * nombre d'elements recuperes depuis la position 0, |
|
| 129 | + * en tenant compte des filtres |
|
| 130 | + * |
|
| 131 | + * @var int |
|
| 132 | + */ |
|
| 133 | + protected $fetched = 0; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Y a t'il une erreur ? |
|
| 137 | + * |
|
| 138 | + * @var bool |
|
| 139 | + **/ |
|
| 140 | + protected $err = false; |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Drapeau a activer en cas d'echec |
|
| 144 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | + */ |
|
| 146 | + public function err() { |
|
| 147 | + if (method_exists($this->iter, 'err')) { |
|
| 148 | + return $this->iter->err(); |
|
| 149 | + } |
|
| 150 | + if (property_exists($this->iter, 'err')) { |
|
| 151 | + return $this->iter->err; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | + parent::__construct($iter); |
|
| 159 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | + |
|
| 161 | + // recuperer l'iterateur transmis |
|
| 162 | + $this->iter = $this->getInnerIterator(); |
|
| 163 | + $this->command = $command; |
|
| 164 | + $this->info = $info; |
|
| 165 | + $this->pos = 0; |
|
| 166 | + $this->fetched = 0; |
|
| 167 | + |
|
| 168 | + // chercher la liste des champs a retourner par |
|
| 169 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | + $this->calculer_select(); |
|
| 172 | + $this->calculer_filtres(); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | + if (isset($this->iter->err)) { |
|
| 177 | + $this->err = $this->iter->err; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | + //$this->total = $this->count(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + // calcule les elements a retournes par fetch() |
|
| 186 | + // enleve les elements inutiles du select() |
|
| 187 | + // |
|
| 188 | + private function calculer_select() { |
|
| 189 | + if ($select = &$this->command['select']) { |
|
| 190 | + foreach ($select as $s) { |
|
| 191 | + // /!\ $s = '.nom' |
|
| 192 | + if ($s[0] == '.') { |
|
| 193 | + $s = substr($s, 1); |
|
| 194 | + } |
|
| 195 | + $this->select[] = $s; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // recuperer la valeur d'une balise #X |
|
| 201 | + // en fonction des methodes |
|
| 202 | + // et proprietes disponibles |
|
| 203 | + public function get_select($nom) { |
|
| 204 | + if (is_object($this->iter) |
|
| 205 | + and method_exists($this->iter, $nom) |
|
| 206 | + ) { |
|
| 207 | + try { |
|
| 208 | + return $this->iter->$nom(); |
|
| 209 | + } catch (Exception $e) { |
|
| 210 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 211 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 213 | + |
|
| 214 | + return ''; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + /* |
|
| 218 | 218 | if (property_exists($this->iter, $nom)) { |
| 219 | 219 | return $this->iter->$nom; |
| 220 | 220 | }*/ |
| 221 | - // cle et valeur par defaut |
|
| 222 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 223 | - if (in_array($nom, array('cle', 'valeur')) |
|
| 224 | - and method_exists($this, $nom) |
|
| 225 | - ) { |
|
| 226 | - return $this->$nom(); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // Par defaut chercher en xpath dans la valeur() |
|
| 230 | - return table_valeur($this->valeur(), $nom, null); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - private function calculer_filtres() { |
|
| 235 | - |
|
| 236 | - // Issu de calculer_select() de public/composer L.519 |
|
| 237 | - // TODO: externaliser... |
|
| 238 | - // |
|
| 239 | - // retirer les criteres vides: |
|
| 240 | - // {X ?} avec X absent de l'URL |
|
| 241 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 242 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 243 | - if ($where = &$this->command['where']) { |
|
| 244 | - foreach ($where as $k => $v) { |
|
| 245 | - if (is_array($v)) { |
|
| 246 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 247 | - $op = false; |
|
| 248 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 249 | - $op = false; |
|
| 250 | - } else { |
|
| 251 | - $op = $v[0] ? $v[0] : $v; |
|
| 252 | - } |
|
| 253 | - } else { |
|
| 254 | - $op = $v; |
|
| 255 | - } |
|
| 256 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 257 | - unset($where[$k]); |
|
| 258 | - } |
|
| 259 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 260 | - if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 261 | - $this->ajouter_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 262 | - unset($op, $where[$k]); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - foreach ($where as $k => $v) { |
|
| 266 | - // 3 possibilites : count($v) = |
|
| 267 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 268 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 269 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 270 | - |
|
| 271 | - // 1 : forcement traite par un critere, on passe |
|
| 272 | - if (!$v or count($v) == 1) { |
|
| 273 | - continue; |
|
| 274 | - } |
|
| 275 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 276 | - $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 277 | - } |
|
| 278 | - if (count($v) == 3) { |
|
| 279 | - $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - // critere {2,7} |
|
| 285 | - if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 286 | - $limit = explode(',', $this->command['limit']); |
|
| 287 | - $this->offset = $limit[0]; |
|
| 288 | - $this->limit = $limit[1]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // Creer la fonction de filtrage sur $this |
|
| 292 | - if ($this->filtre) { |
|
| 293 | - $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 294 | - $this->func_filtre = function () use ($filtres) { |
|
| 295 | - return eval($filtres); |
|
| 296 | - }; |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - |
|
| 301 | - protected function ajouter_filtre($cle, $op, $valeur, $not = false) { |
|
| 302 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 303 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 304 | - return; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 308 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 309 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 310 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 311 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 312 | - |
|
| 313 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 314 | - # return; |
|
| 315 | - |
|
| 316 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 317 | - |
|
| 318 | - $filtre = ''; |
|
| 319 | - |
|
| 320 | - if ($op == 'REGEXP') { |
|
| 321 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 322 | - $op = ''; |
|
| 323 | - } else { |
|
| 324 | - if ($op == 'LIKE') { |
|
| 325 | - $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 326 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 327 | - $op = ''; |
|
| 328 | - } else { |
|
| 329 | - if ($op == '=') { |
|
| 330 | - $op = '=='; |
|
| 331 | - } else { |
|
| 332 | - if ($op == 'IN') { |
|
| 333 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 334 | - $op = ''; |
|
| 335 | - } else { |
|
| 336 | - if (!in_array($op, array('<', '<=', '>', '>='))) { |
|
| 337 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 338 | - $op = ''; |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if ($op) { |
|
| 346 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if ($not) { |
|
| 350 | - $filtre = "!($filtre)"; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if ($filtre) { |
|
| 354 | - $this->filtre[] = $filtre; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - public function next() { |
|
| 360 | - $this->pos++; |
|
| 361 | - parent::next(); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * revient au depart |
|
| 366 | - * |
|
| 367 | - * @return void |
|
| 368 | - */ |
|
| 369 | - public function rewind() { |
|
| 370 | - $this->pos = 0; |
|
| 371 | - $this->fetched = 0; |
|
| 372 | - parent::rewind(); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - # Extension SPIP des iterateurs PHP |
|
| 377 | - /** |
|
| 378 | - * type de l'iterateur |
|
| 379 | - * |
|
| 380 | - * @var string |
|
| 381 | - */ |
|
| 382 | - protected $type; |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * parametres de l'iterateur |
|
| 386 | - * |
|
| 387 | - * @var array |
|
| 388 | - */ |
|
| 389 | - protected $command; |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * infos de compilateur |
|
| 393 | - * |
|
| 394 | - * @var array |
|
| 395 | - */ |
|
| 396 | - protected $info; |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * position courante de l'iterateur |
|
| 400 | - * |
|
| 401 | - * @var int |
|
| 402 | - */ |
|
| 403 | - protected $pos = null; |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * nombre total resultats dans l'iterateur |
|
| 407 | - * |
|
| 408 | - * @var int |
|
| 409 | - */ |
|
| 410 | - protected $total = null; |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * nombre maximal de recherche pour $total |
|
| 414 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 415 | - */ |
|
| 416 | - protected $max = 100000; |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Liste des champs a inserer dans les $row |
|
| 421 | - * retournes par ->fetch() |
|
| 422 | - */ |
|
| 423 | - protected $select = array(); |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * aller a la position absolue n, |
|
| 428 | - * comptee depuis le debut |
|
| 429 | - * |
|
| 430 | - * @param int $n |
|
| 431 | - * absolute pos |
|
| 432 | - * @param string $continue |
|
| 433 | - * param for sql_ api |
|
| 434 | - * @return bool |
|
| 435 | - * success or fail if not implemented |
|
| 436 | - */ |
|
| 437 | - public function seek($n = 0, $continue = null) { |
|
| 438 | - if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 439 | - $this->seek_loop($n); |
|
| 440 | - } |
|
| 441 | - $this->pos = $n; |
|
| 442 | - $this->fetched = $n; |
|
| 443 | - |
|
| 444 | - return true; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /* |
|
| 221 | + // cle et valeur par defaut |
|
| 222 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 223 | + if (in_array($nom, array('cle', 'valeur')) |
|
| 224 | + and method_exists($this, $nom) |
|
| 225 | + ) { |
|
| 226 | + return $this->$nom(); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // Par defaut chercher en xpath dans la valeur() |
|
| 230 | + return table_valeur($this->valeur(), $nom, null); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + private function calculer_filtres() { |
|
| 235 | + |
|
| 236 | + // Issu de calculer_select() de public/composer L.519 |
|
| 237 | + // TODO: externaliser... |
|
| 238 | + // |
|
| 239 | + // retirer les criteres vides: |
|
| 240 | + // {X ?} avec X absent de l'URL |
|
| 241 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 242 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 243 | + if ($where = &$this->command['where']) { |
|
| 244 | + foreach ($where as $k => $v) { |
|
| 245 | + if (is_array($v)) { |
|
| 246 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 247 | + $op = false; |
|
| 248 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 249 | + $op = false; |
|
| 250 | + } else { |
|
| 251 | + $op = $v[0] ? $v[0] : $v; |
|
| 252 | + } |
|
| 253 | + } else { |
|
| 254 | + $op = $v; |
|
| 255 | + } |
|
| 256 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 257 | + unset($where[$k]); |
|
| 258 | + } |
|
| 259 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 260 | + if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 261 | + $this->ajouter_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 262 | + unset($op, $where[$k]); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + foreach ($where as $k => $v) { |
|
| 266 | + // 3 possibilites : count($v) = |
|
| 267 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 268 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 269 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 270 | + |
|
| 271 | + // 1 : forcement traite par un critere, on passe |
|
| 272 | + if (!$v or count($v) == 1) { |
|
| 273 | + continue; |
|
| 274 | + } |
|
| 275 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 276 | + $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 277 | + } |
|
| 278 | + if (count($v) == 3) { |
|
| 279 | + $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + // critere {2,7} |
|
| 285 | + if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 286 | + $limit = explode(',', $this->command['limit']); |
|
| 287 | + $this->offset = $limit[0]; |
|
| 288 | + $this->limit = $limit[1]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // Creer la fonction de filtrage sur $this |
|
| 292 | + if ($this->filtre) { |
|
| 293 | + $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 294 | + $this->func_filtre = function () use ($filtres) { |
|
| 295 | + return eval($filtres); |
|
| 296 | + }; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + |
|
| 301 | + protected function ajouter_filtre($cle, $op, $valeur, $not = false) { |
|
| 302 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 303 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 304 | + return; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 308 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 309 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 310 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 311 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 312 | + |
|
| 313 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 314 | + # return; |
|
| 315 | + |
|
| 316 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 317 | + |
|
| 318 | + $filtre = ''; |
|
| 319 | + |
|
| 320 | + if ($op == 'REGEXP') { |
|
| 321 | + $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 322 | + $op = ''; |
|
| 323 | + } else { |
|
| 324 | + if ($op == 'LIKE') { |
|
| 325 | + $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 326 | + $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 327 | + $op = ''; |
|
| 328 | + } else { |
|
| 329 | + if ($op == '=') { |
|
| 330 | + $op = '=='; |
|
| 331 | + } else { |
|
| 332 | + if ($op == 'IN') { |
|
| 333 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 334 | + $op = ''; |
|
| 335 | + } else { |
|
| 336 | + if (!in_array($op, array('<', '<=', '>', '>='))) { |
|
| 337 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 338 | + $op = ''; |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if ($op) { |
|
| 346 | + $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if ($not) { |
|
| 350 | + $filtre = "!($filtre)"; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if ($filtre) { |
|
| 354 | + $this->filtre[] = $filtre; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + public function next() { |
|
| 360 | + $this->pos++; |
|
| 361 | + parent::next(); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * revient au depart |
|
| 366 | + * |
|
| 367 | + * @return void |
|
| 368 | + */ |
|
| 369 | + public function rewind() { |
|
| 370 | + $this->pos = 0; |
|
| 371 | + $this->fetched = 0; |
|
| 372 | + parent::rewind(); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + # Extension SPIP des iterateurs PHP |
|
| 377 | + /** |
|
| 378 | + * type de l'iterateur |
|
| 379 | + * |
|
| 380 | + * @var string |
|
| 381 | + */ |
|
| 382 | + protected $type; |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * parametres de l'iterateur |
|
| 386 | + * |
|
| 387 | + * @var array |
|
| 388 | + */ |
|
| 389 | + protected $command; |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * infos de compilateur |
|
| 393 | + * |
|
| 394 | + * @var array |
|
| 395 | + */ |
|
| 396 | + protected $info; |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * position courante de l'iterateur |
|
| 400 | + * |
|
| 401 | + * @var int |
|
| 402 | + */ |
|
| 403 | + protected $pos = null; |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * nombre total resultats dans l'iterateur |
|
| 407 | + * |
|
| 408 | + * @var int |
|
| 409 | + */ |
|
| 410 | + protected $total = null; |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * nombre maximal de recherche pour $total |
|
| 414 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 415 | + */ |
|
| 416 | + protected $max = 100000; |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Liste des champs a inserer dans les $row |
|
| 421 | + * retournes par ->fetch() |
|
| 422 | + */ |
|
| 423 | + protected $select = array(); |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * aller a la position absolue n, |
|
| 428 | + * comptee depuis le debut |
|
| 429 | + * |
|
| 430 | + * @param int $n |
|
| 431 | + * absolute pos |
|
| 432 | + * @param string $continue |
|
| 433 | + * param for sql_ api |
|
| 434 | + * @return bool |
|
| 435 | + * success or fail if not implemented |
|
| 436 | + */ |
|
| 437 | + public function seek($n = 0, $continue = null) { |
|
| 438 | + if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 439 | + $this->seek_loop($n); |
|
| 440 | + } |
|
| 441 | + $this->pos = $n; |
|
| 442 | + $this->fetched = $n; |
|
| 443 | + |
|
| 444 | + return true; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /* |
|
| 448 | 448 | * aller a la position $n en parcourant |
| 449 | 449 | * un par un tous les elements |
| 450 | 450 | */ |
| 451 | - private function seek_loop($n) { |
|
| 452 | - if ($this->pos > $n) { |
|
| 453 | - $this->rewind(); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - while ($this->pos < $n and $this->valid()) { |
|
| 457 | - $this->next(); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - return true; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Avancer de $saut pas |
|
| 465 | - * |
|
| 466 | - * @param $saut |
|
| 467 | - * @param $max |
|
| 468 | - * @return int |
|
| 469 | - */ |
|
| 470 | - public function skip($saut, $max = null) { |
|
| 471 | - // pas de saut en arriere autorise pour cette fonction |
|
| 472 | - if (($saut = intval($saut)) <= 0) { |
|
| 473 | - return $this->pos; |
|
| 474 | - } |
|
| 475 | - $seek = $this->pos + $saut; |
|
| 476 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 477 | - // et on sort |
|
| 478 | - if (is_null($max)) { |
|
| 479 | - $max = $this->count(); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - if ($seek >= $max or $seek >= $this->count()) { |
|
| 483 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 484 | - $this->free(); |
|
| 485 | - |
|
| 486 | - return $max; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - $this->seek($seek); |
|
| 490 | - |
|
| 491 | - return $this->pos; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Renvoyer un tableau des donnees correspondantes |
|
| 496 | - * a la position courante de l'iterateur |
|
| 497 | - * en controlant si on respecte le filtre |
|
| 498 | - * Appliquer aussi le critere {offset,limit} |
|
| 499 | - * |
|
| 500 | - * @return array|bool |
|
| 501 | - */ |
|
| 502 | - public function fetch() { |
|
| 503 | - if (method_exists($this->iter, 'fetch')) { |
|
| 504 | - return $this->iter->fetch(); |
|
| 505 | - } else { |
|
| 506 | - |
|
| 507 | - while ($this->valid() |
|
| 508 | - and ( |
|
| 509 | - !$this->accept() |
|
| 510 | - or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 511 | - )) { |
|
| 512 | - $this->next(); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - if (!$this->valid()) { |
|
| 516 | - return false; |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - if (isset($this->limit) |
|
| 520 | - and $this->fetched > $this->offset + $this->limit |
|
| 521 | - ) { |
|
| 522 | - return false; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $r = array(); |
|
| 526 | - foreach ($this->select as $nom) { |
|
| 527 | - $r[$nom] = $this->get_select($nom); |
|
| 528 | - } |
|
| 529 | - $this->next(); |
|
| 530 | - |
|
| 531 | - return $r; |
|
| 532 | - } |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - // retourner la cle pour #CLE |
|
| 536 | - public function cle() { |
|
| 537 | - return $this->key(); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // retourner la valeur pour #VALEUR |
|
| 541 | - public function valeur() { |
|
| 542 | - return $this->current(); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Accepte-t-on l'entree courante lue ? |
|
| 547 | - * On execute les filtres pour le savoir. |
|
| 548 | - **/ |
|
| 549 | - public function accept() { |
|
| 550 | - if ($f = $this->func_filtre) { |
|
| 551 | - return $f(); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - return true; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * liberer la ressource |
|
| 559 | - * |
|
| 560 | - * @return bool |
|
| 561 | - */ |
|
| 562 | - public function free() { |
|
| 563 | - if (method_exists($this->iter, 'free')) { |
|
| 564 | - $this->iter->free(); |
|
| 565 | - } |
|
| 566 | - $this->pos = $this->total = 0; |
|
| 567 | - |
|
| 568 | - return true; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Compter le nombre total de resultats |
|
| 573 | - * pour #TOTAL_BOUCLE |
|
| 574 | - * |
|
| 575 | - * @return int |
|
| 576 | - */ |
|
| 577 | - public function count() { |
|
| 578 | - if (is_null($this->total)) { |
|
| 579 | - if (method_exists($this->iter, 'count') |
|
| 580 | - and !$this->func_filtre |
|
| 581 | - ) { |
|
| 582 | - return $this->total = $this->iter->count(); |
|
| 583 | - } else { |
|
| 584 | - // compter les lignes et rembobiner |
|
| 585 | - $total = 0; |
|
| 586 | - $pos = $this->pos; // sauver la position |
|
| 587 | - $this->rewind(); |
|
| 588 | - while ($this->fetch() and $total < $this->max) { |
|
| 589 | - $total++; |
|
| 590 | - } |
|
| 591 | - $this->seek($pos); |
|
| 592 | - $this->total = $total; |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - return $this->total; |
|
| 597 | - } |
|
| 451 | + private function seek_loop($n) { |
|
| 452 | + if ($this->pos > $n) { |
|
| 453 | + $this->rewind(); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + while ($this->pos < $n and $this->valid()) { |
|
| 457 | + $this->next(); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + return true; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Avancer de $saut pas |
|
| 465 | + * |
|
| 466 | + * @param $saut |
|
| 467 | + * @param $max |
|
| 468 | + * @return int |
|
| 469 | + */ |
|
| 470 | + public function skip($saut, $max = null) { |
|
| 471 | + // pas de saut en arriere autorise pour cette fonction |
|
| 472 | + if (($saut = intval($saut)) <= 0) { |
|
| 473 | + return $this->pos; |
|
| 474 | + } |
|
| 475 | + $seek = $this->pos + $saut; |
|
| 476 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 477 | + // et on sort |
|
| 478 | + if (is_null($max)) { |
|
| 479 | + $max = $this->count(); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + if ($seek >= $max or $seek >= $this->count()) { |
|
| 483 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 484 | + $this->free(); |
|
| 485 | + |
|
| 486 | + return $max; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + $this->seek($seek); |
|
| 490 | + |
|
| 491 | + return $this->pos; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Renvoyer un tableau des donnees correspondantes |
|
| 496 | + * a la position courante de l'iterateur |
|
| 497 | + * en controlant si on respecte le filtre |
|
| 498 | + * Appliquer aussi le critere {offset,limit} |
|
| 499 | + * |
|
| 500 | + * @return array|bool |
|
| 501 | + */ |
|
| 502 | + public function fetch() { |
|
| 503 | + if (method_exists($this->iter, 'fetch')) { |
|
| 504 | + return $this->iter->fetch(); |
|
| 505 | + } else { |
|
| 506 | + |
|
| 507 | + while ($this->valid() |
|
| 508 | + and ( |
|
| 509 | + !$this->accept() |
|
| 510 | + or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 511 | + )) { |
|
| 512 | + $this->next(); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + if (!$this->valid()) { |
|
| 516 | + return false; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + if (isset($this->limit) |
|
| 520 | + and $this->fetched > $this->offset + $this->limit |
|
| 521 | + ) { |
|
| 522 | + return false; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $r = array(); |
|
| 526 | + foreach ($this->select as $nom) { |
|
| 527 | + $r[$nom] = $this->get_select($nom); |
|
| 528 | + } |
|
| 529 | + $this->next(); |
|
| 530 | + |
|
| 531 | + return $r; |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + // retourner la cle pour #CLE |
|
| 536 | + public function cle() { |
|
| 537 | + return $this->key(); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // retourner la valeur pour #VALEUR |
|
| 541 | + public function valeur() { |
|
| 542 | + return $this->current(); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Accepte-t-on l'entree courante lue ? |
|
| 547 | + * On execute les filtres pour le savoir. |
|
| 548 | + **/ |
|
| 549 | + public function accept() { |
|
| 550 | + if ($f = $this->func_filtre) { |
|
| 551 | + return $f(); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + return true; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * liberer la ressource |
|
| 559 | + * |
|
| 560 | + * @return bool |
|
| 561 | + */ |
|
| 562 | + public function free() { |
|
| 563 | + if (method_exists($this->iter, 'free')) { |
|
| 564 | + $this->iter->free(); |
|
| 565 | + } |
|
| 566 | + $this->pos = $this->total = 0; |
|
| 567 | + |
|
| 568 | + return true; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Compter le nombre total de resultats |
|
| 573 | + * pour #TOTAL_BOUCLE |
|
| 574 | + * |
|
| 575 | + * @return int |
|
| 576 | + */ |
|
| 577 | + public function count() { |
|
| 578 | + if (is_null($this->total)) { |
|
| 579 | + if (method_exists($this->iter, 'count') |
|
| 580 | + and !$this->func_filtre |
|
| 581 | + ) { |
|
| 582 | + return $this->total = $this->iter->count(); |
|
| 583 | + } else { |
|
| 584 | + // compter les lignes et rembobiner |
|
| 585 | + $total = 0; |
|
| 586 | + $pos = $this->pos; // sauver la position |
|
| 587 | + $this->rewind(); |
|
| 588 | + while ($this->fetch() and $total < $this->max) { |
|
| 589 | + $total++; |
|
| 590 | + } |
|
| 591 | + $this->seek($pos); |
|
| 592 | + $this->total = $total; |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + return $this->total; |
|
| 597 | + } |
|
| 598 | 598 | |
| 599 | 599 | } |
@@ -231,7 +231,7 @@ |
||
| 231 | 231 | * |
| 232 | 232 | * @param array $depart |
| 233 | 233 | * @param array $arrivee |
| 234 | - * @param string|array $col |
|
| 234 | + * @param string $col |
|
| 235 | 235 | * @return bool |
| 236 | 236 | */ |
| 237 | 237 | function nogroupby_if($depart, $arrivee, $col) { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * Chaine sinon : le nom du champ (non décomposable donc) |
| 34 | 34 | */ |
| 35 | 35 | function decompose_champ_id_objet($champ) { |
| 36 | - if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | - return array('id_objet', 'objet', objet_type($champ)); |
|
| 38 | - } |
|
| 36 | + if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | + return array('id_objet', 'objet', objet_type($champ)); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return $champ; |
|
| 40 | + return $champ; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -56,20 +56,20 @@ discard block |
||
| 56 | 56 | * - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer |
| 57 | 57 | */ |
| 58 | 58 | function trouver_champs_decomposes($champ, $desc) { |
| 59 | - if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 60 | - or array_key_exists($champ, $desc['field']) |
|
| 61 | - ) { |
|
| 62 | - return array($champ); |
|
| 63 | - } |
|
| 64 | - // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 65 | - if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 66 | - array_pop($decompose); |
|
| 67 | - if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 68 | - return $decompose; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return array($champ); |
|
| 59 | + if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 60 | + or array_key_exists($champ, $desc['field']) |
|
| 61 | + ) { |
|
| 62 | + return array($champ); |
|
| 63 | + } |
|
| 64 | + // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 65 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 66 | + array_pop($decompose); |
|
| 67 | + if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 68 | + return $decompose; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return array($champ); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -99,23 +99,23 @@ discard block |
||
| 99 | 99 | * Alias de la table de jointure (Lx) |
| 100 | 100 | */ |
| 101 | 101 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
| 102 | - // les jointures minimales sont optimales : |
|
| 103 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 104 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 105 | - $max = 1; |
|
| 106 | - $res = false; |
|
| 107 | - $milieu_exclus = ($col ? $col : array()); |
|
| 108 | - while ($max <= $max_liens and !$res) { |
|
| 109 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 110 | - $max++; |
|
| 111 | - } |
|
| 112 | - if (!$res) { |
|
| 113 | - return ""; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - list($nom, $desc) = $depart; |
|
| 117 | - |
|
| 118 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 102 | + // les jointures minimales sont optimales : |
|
| 103 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 104 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 105 | + $max = 1; |
|
| 106 | + $res = false; |
|
| 107 | + $milieu_exclus = ($col ? $col : array()); |
|
| 108 | + while ($max <= $max_liens and !$res) { |
|
| 109 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 110 | + $max++; |
|
| 111 | + } |
|
| 112 | + if (!$res) { |
|
| 113 | + return ""; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + list($nom, $desc) = $depart; |
|
| 117 | + |
|
| 118 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -154,78 +154,78 @@ discard block |
||
| 154 | 154 | * Alias de la table de jointure (Lx) |
| 155 | 155 | */ |
| 156 | 156 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = array(), $nom = '', $col = '', $echap = true) { |
| 157 | - static $num = array(); |
|
| 158 | - $id_table = ""; |
|
| 159 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 160 | - foreach ($res as $cle => $r) { |
|
| 161 | - list($d, $a, $j) = $r; |
|
| 162 | - if (!$id_table) { |
|
| 163 | - $id_table = $d; |
|
| 164 | - } |
|
| 165 | - $n = ++$cpt; |
|
| 166 | - if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 167 | - list($j1, $j2, $obj, $type) = $j; |
|
| 168 | - // trouver de quel cote est (id_objet,objet) |
|
| 169 | - if ($j1 == "id_$obj") { |
|
| 170 | - $obj = "$id_table.$obj"; |
|
| 171 | - } else { |
|
| 172 | - $obj = "L$n.$obj"; |
|
| 173 | - } |
|
| 174 | - // le where complementaire est envoye dans la jointure et dans le where |
|
| 175 | - // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 176 | - // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 177 | - $boucle->where["JOIN-L$n"] = |
|
| 178 | - $echap ? |
|
| 179 | - array("'='","'$obj'","sql_quote('$type')") |
|
| 180 | - : |
|
| 181 | - array("=","$obj",sql_quote($type)); |
|
| 182 | - $boucle->join["L$n"] = |
|
| 183 | - $echap ? |
|
| 184 | - array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 185 | - : |
|
| 186 | - array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 187 | - } else { |
|
| 188 | - $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 189 | - } |
|
| 190 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - // pas besoin de group by |
|
| 195 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 196 | - // si une seule jointure et sur une table avec primary key formee |
|
| 197 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 198 | - // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 199 | - |
|
| 200 | - if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 201 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // pas de group by |
|
| 205 | - // si une seule jointure |
|
| 206 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 207 | - if (!$pk |
|
| 208 | - and (count($boucle->from) == 2) |
|
| 209 | - and isset($a[1]['key']['PRIMARY KEY']) |
|
| 210 | - and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 211 | - ) { |
|
| 212 | - $pk = true; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 216 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 217 | - if (!$pk) { |
|
| 218 | - foreach ($groups as $id_prim) { |
|
| 219 | - $id_field = $nom . '.' . $id_prim; |
|
| 220 | - if (!in_array($id_field, $boucle->group)) { |
|
| 221 | - $boucle->group[] = $id_field; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $boucle->modificateur['lien'] = true; |
|
| 227 | - |
|
| 228 | - return "L$n"; |
|
| 157 | + static $num = array(); |
|
| 158 | + $id_table = ""; |
|
| 159 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 160 | + foreach ($res as $cle => $r) { |
|
| 161 | + list($d, $a, $j) = $r; |
|
| 162 | + if (!$id_table) { |
|
| 163 | + $id_table = $d; |
|
| 164 | + } |
|
| 165 | + $n = ++$cpt; |
|
| 166 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 167 | + list($j1, $j2, $obj, $type) = $j; |
|
| 168 | + // trouver de quel cote est (id_objet,objet) |
|
| 169 | + if ($j1 == "id_$obj") { |
|
| 170 | + $obj = "$id_table.$obj"; |
|
| 171 | + } else { |
|
| 172 | + $obj = "L$n.$obj"; |
|
| 173 | + } |
|
| 174 | + // le where complementaire est envoye dans la jointure et dans le where |
|
| 175 | + // on utilise une clé qui le relie a la jointure pour que l'optimiseur |
|
| 176 | + // sache qu'il peut enlever ce where si il enleve la jointure |
|
| 177 | + $boucle->where["JOIN-L$n"] = |
|
| 178 | + $echap ? |
|
| 179 | + array("'='","'$obj'","sql_quote('$type')") |
|
| 180 | + : |
|
| 181 | + array("=","$obj",sql_quote($type)); |
|
| 182 | + $boucle->join["L$n"] = |
|
| 183 | + $echap ? |
|
| 184 | + array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 185 | + : |
|
| 186 | + array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 187 | + } else { |
|
| 188 | + $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 189 | + } |
|
| 190 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + // pas besoin de group by |
|
| 195 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 196 | + // si une seule jointure et sur une table avec primary key formee |
|
| 197 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 198 | + // et operateur d'egalite (https://core.spip.net/issues/477) |
|
| 199 | + |
|
| 200 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 201 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // pas de group by |
|
| 205 | + // si une seule jointure |
|
| 206 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 207 | + if (!$pk |
|
| 208 | + and (count($boucle->from) == 2) |
|
| 209 | + and isset($a[1]['key']['PRIMARY KEY']) |
|
| 210 | + and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 211 | + ) { |
|
| 212 | + $pk = true; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 216 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 217 | + if (!$pk) { |
|
| 218 | + foreach ($groups as $id_prim) { |
|
| 219 | + $id_field = $nom . '.' . $id_prim; |
|
| 220 | + if (!in_array($id_field, $boucle->group)) { |
|
| 221 | + $boucle->group[] = $id_field; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $boucle->modificateur['lien'] = true; |
|
| 227 | + |
|
| 228 | + return "L$n"; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -240,16 +240,16 @@ discard block |
||
| 240 | 240 | * @return bool |
| 241 | 241 | */ |
| 242 | 242 | function nogroupby_if($depart, $arrivee, $col) { |
| 243 | - $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 244 | - if (!$pk) { |
|
| 245 | - return false; |
|
| 246 | - } |
|
| 247 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 248 | - if (is_array($col)) { |
|
| 249 | - $col = implode(', *', $col); |
|
| 250 | - } // cas id_objet, objet |
|
| 251 | - return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 252 | - preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 243 | + $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 244 | + if (!$pk) { |
|
| 245 | + return false; |
|
| 246 | + } |
|
| 247 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 248 | + if (is_array($col)) { |
|
| 249 | + $col = implode(', *', $col); |
|
| 250 | + } // cas id_objet, objet |
|
| 251 | + return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 252 | + preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -267,46 +267,46 @@ discard block |
||
| 267 | 267 | */ |
| 268 | 268 | function liste_champs_jointures($nom, $desc, $primary = false) { |
| 269 | 269 | |
| 270 | - static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 270 | + static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 271 | 271 | |
| 272 | - // si cle primaire demandee, la privilegier |
|
| 273 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 274 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 275 | - } |
|
| 272 | + // si cle primaire demandee, la privilegier |
|
| 273 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 274 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - // les champs declares explicitement pour les jointures |
|
| 278 | - if (isset($desc['join'])) { |
|
| 279 | - return $desc['join']; |
|
| 280 | - } |
|
| 281 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 277 | + // les champs declares explicitement pour les jointures |
|
| 278 | + if (isset($desc['join'])) { |
|
| 279 | + return $desc['join']; |
|
| 280 | + } |
|
| 281 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 282 | 282 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 283 | 283 | |
| 284 | - // si pas de cle, c'est fichu |
|
| 285 | - if (!isset($desc['key'])) { |
|
| 286 | - return array(); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - // si cle primaire |
|
| 290 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 291 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - // ici on se rabat sur les cles secondaires, |
|
| 295 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 296 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 297 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 298 | - |
|
| 299 | - $join = array(); |
|
| 300 | - foreach ($desc['key'] as $v) { |
|
| 301 | - $join = split_key($v, $join); |
|
| 302 | - } |
|
| 303 | - foreach ($join as $k) { |
|
| 304 | - if (in_array($k, $nojoin)) { |
|
| 305 | - unset($join[$k]); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - return $join; |
|
| 284 | + // si pas de cle, c'est fichu |
|
| 285 | + if (!isset($desc['key'])) { |
|
| 286 | + return array(); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + // si cle primaire |
|
| 290 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 291 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + // ici on se rabat sur les cles secondaires, |
|
| 295 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 296 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 297 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 298 | + |
|
| 299 | + $join = array(); |
|
| 300 | + foreach ($desc['key'] as $v) { |
|
| 301 | + $join = split_key($v, $join); |
|
| 302 | + } |
|
| 303 | + foreach ($join as $k) { |
|
| 304 | + if (in_array($k, $nojoin)) { |
|
| 305 | + unset($join[$k]); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + return $join; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -317,14 +317,14 @@ discard block |
||
| 317 | 317 | * @return array |
| 318 | 318 | */ |
| 319 | 319 | function split_key($v, $join = array()) { |
| 320 | - foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 321 | - if (strpos($k, '(') !== false) { |
|
| 322 | - $k = explode('(', $k); |
|
| 323 | - $k = trim(reset($k)); |
|
| 324 | - } |
|
| 325 | - $join[$k] = $k; |
|
| 326 | - } |
|
| 327 | - return $join; |
|
| 320 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 321 | + if (strpos($k, '(') !== false) { |
|
| 322 | + $k = explode('(', $k); |
|
| 323 | + $k = trim(reset($k)); |
|
| 324 | + } |
|
| 325 | + $join[$k] = $k; |
|
| 326 | + } |
|
| 327 | + return $join; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -347,126 +347,126 @@ discard block |
||
| 347 | 347 | * @return array |
| 348 | 348 | */ |
| 349 | 349 | function calculer_chaine_jointures( |
| 350 | - &$boucle, |
|
| 351 | - $depart, |
|
| 352 | - $arrivee, |
|
| 353 | - $vu = array(), |
|
| 354 | - $milieu_exclus = array(), |
|
| 355 | - $max_liens = 5 |
|
| 350 | + &$boucle, |
|
| 351 | + $depart, |
|
| 352 | + $arrivee, |
|
| 353 | + $vu = array(), |
|
| 354 | + $milieu_exclus = array(), |
|
| 355 | + $max_liens = 5 |
|
| 356 | 356 | ) { |
| 357 | - static $trouver_table; |
|
| 358 | - if (!$trouver_table) { |
|
| 359 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if (is_string($milieu_exclus)) { |
|
| 363 | - $milieu_exclus = array($milieu_exclus); |
|
| 364 | - } |
|
| 365 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 366 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 367 | - if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 368 | - $milieu_exclus[] = 'objet'; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - list($dnom, $ddesc) = $depart; |
|
| 372 | - list($anom, $adesc) = $arrivee; |
|
| 373 | - if (!count($vu)) { |
|
| 374 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 375 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - $akeys = array(); |
|
| 379 | - foreach ($adesc['key'] as $k) { |
|
| 380 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 381 | - $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 385 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 386 | - |
|
| 387 | - // cles candidates au depart |
|
| 388 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 389 | - // enlever les cles dde depart exclues par l'appel |
|
| 390 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 391 | - |
|
| 392 | - $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 393 | - |
|
| 394 | - if ($v) { |
|
| 395 | - return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 399 | - if (count(array_intersect(array('id_objet', 'objet'), $keys)) == 2) { |
|
| 400 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 401 | - // id_objet,objet |
|
| 402 | - // si oui on la prend |
|
| 403 | - foreach ($akeys as $key) { |
|
| 404 | - $v = decompose_champ_id_objet($key); |
|
| 405 | - if (is_array($v)) { |
|
| 406 | - $objet = array_shift($v); // objet,'article' |
|
| 407 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 408 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 409 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - } else { |
|
| 413 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 414 | - // id_objet,objet a l'arrivee |
|
| 415 | - // si oui on la prend |
|
| 416 | - foreach ($keys as $key) { |
|
| 417 | - if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 418 | - if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 419 | - $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 420 | - array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 421 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 427 | - if ($max_liens <= 1) { |
|
| 428 | - return array(); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - // sinon essayer de passer par une autre table |
|
| 432 | - $new = $vu; |
|
| 433 | - foreach ($boucle->jointures as $v) { |
|
| 434 | - if ($v |
|
| 435 | - and !in_array($v, $vu) |
|
| 436 | - and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 437 | - and !in_array($def['table_sql'], $vu) |
|
| 438 | - ) { |
|
| 439 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 440 | - // ie la cle de la jointure precedente |
|
| 441 | - $test_cles = $milieu_exclus; |
|
| 442 | - $new[] = $v; |
|
| 443 | - $max_iter = 50; // securite |
|
| 444 | - while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, |
|
| 445 | - $test_cles, 1)) |
|
| 446 | - and $max_iter--) { |
|
| 447 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 448 | - $milieu = end($jointure_directe_possible); |
|
| 449 | - $exclure_fin = $milieu_exclus; |
|
| 450 | - if (is_string($milieu)) { |
|
| 451 | - $exclure_fin[] = $milieu; |
|
| 452 | - $test_cles[] = $milieu; |
|
| 453 | - } else { |
|
| 454 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 455 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 456 | - } |
|
| 457 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 458 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 459 | - $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 460 | - if ($r) { |
|
| 461 | - array_unshift($r, $jointure_directe_possible); |
|
| 462 | - |
|
| 463 | - return $r; |
|
| 464 | - } |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - return array(); |
|
| 357 | + static $trouver_table; |
|
| 358 | + if (!$trouver_table) { |
|
| 359 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if (is_string($milieu_exclus)) { |
|
| 363 | + $milieu_exclus = array($milieu_exclus); |
|
| 364 | + } |
|
| 365 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 366 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 367 | + if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 368 | + $milieu_exclus[] = 'objet'; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + list($dnom, $ddesc) = $depart; |
|
| 372 | + list($anom, $adesc) = $arrivee; |
|
| 373 | + if (!count($vu)) { |
|
| 374 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 375 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + $akeys = array(); |
|
| 379 | + foreach ($adesc['key'] as $k) { |
|
| 380 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 381 | + $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 385 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 386 | + |
|
| 387 | + // cles candidates au depart |
|
| 388 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 389 | + // enlever les cles dde depart exclues par l'appel |
|
| 390 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 391 | + |
|
| 392 | + $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 393 | + |
|
| 394 | + if ($v) { |
|
| 395 | + return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 399 | + if (count(array_intersect(array('id_objet', 'objet'), $keys)) == 2) { |
|
| 400 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 401 | + // id_objet,objet |
|
| 402 | + // si oui on la prend |
|
| 403 | + foreach ($akeys as $key) { |
|
| 404 | + $v = decompose_champ_id_objet($key); |
|
| 405 | + if (is_array($v)) { |
|
| 406 | + $objet = array_shift($v); // objet,'article' |
|
| 407 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 408 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 409 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + } else { |
|
| 413 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 414 | + // id_objet,objet a l'arrivee |
|
| 415 | + // si oui on la prend |
|
| 416 | + foreach ($keys as $key) { |
|
| 417 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 418 | + if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 419 | + $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 420 | + array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 421 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 427 | + if ($max_liens <= 1) { |
|
| 428 | + return array(); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + // sinon essayer de passer par une autre table |
|
| 432 | + $new = $vu; |
|
| 433 | + foreach ($boucle->jointures as $v) { |
|
| 434 | + if ($v |
|
| 435 | + and !in_array($v, $vu) |
|
| 436 | + and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 437 | + and !in_array($def['table_sql'], $vu) |
|
| 438 | + ) { |
|
| 439 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 440 | + // ie la cle de la jointure precedente |
|
| 441 | + $test_cles = $milieu_exclus; |
|
| 442 | + $new[] = $v; |
|
| 443 | + $max_iter = 50; // securite |
|
| 444 | + while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, |
|
| 445 | + $test_cles, 1)) |
|
| 446 | + and $max_iter--) { |
|
| 447 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 448 | + $milieu = end($jointure_directe_possible); |
|
| 449 | + $exclure_fin = $milieu_exclus; |
|
| 450 | + if (is_string($milieu)) { |
|
| 451 | + $exclure_fin[] = $milieu; |
|
| 452 | + $test_cles[] = $milieu; |
|
| 453 | + } else { |
|
| 454 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 455 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 456 | + } |
|
| 457 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 458 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 459 | + $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 460 | + if ($r) { |
|
| 461 | + array_unshift($r, $jointure_directe_possible); |
|
| 462 | + |
|
| 463 | + return $r; |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + return array(); |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -477,18 +477,18 @@ discard block |
||
| 477 | 477 | * @return array |
| 478 | 478 | */ |
| 479 | 479 | function trouver_cles_table($keys) { |
| 480 | - $res = array(); |
|
| 481 | - foreach ($keys as $v) { |
|
| 482 | - if (!strpos($v, ",")) { |
|
| 483 | - $res[$v] = 1; |
|
| 484 | - } else { |
|
| 485 | - foreach (preg_split("/\s*,\s*/", $v) as $k) { |
|
| 486 | - $res[$k] = 1; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - return array_keys($res); |
|
| 480 | + $res = array(); |
|
| 481 | + foreach ($keys as $v) { |
|
| 482 | + if (!strpos($v, ",")) { |
|
| 483 | + $res[$v] = 1; |
|
| 484 | + } else { |
|
| 485 | + foreach (preg_split("/\s*,\s*/", $v) as $k) { |
|
| 486 | + $res[$k] = 1; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + return array_keys($res); |
|
| 492 | 492 | } |
| 493 | 493 | |
| 494 | 494 | |
@@ -515,33 +515,33 @@ discard block |
||
| 515 | 515 | * - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple) |
| 516 | 516 | */ |
| 517 | 517 | function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) { |
| 518 | - static $trouver_table = ''; |
|
| 519 | - if (!$trouver_table) { |
|
| 520 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - if (!is_array($cle)) { |
|
| 524 | - $cle = array($cle); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - foreach ($tables as $k => $table) { |
|
| 528 | - if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 529 | - if (isset($desc['field']) |
|
| 530 | - // verifier que toutes les cles cherchees sont la |
|
| 531 | - and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 532 | - // si on sait ou on veut arriver, il faut que ca colle |
|
| 533 | - and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 534 | - ) { |
|
| 535 | - return array( |
|
| 536 | - 'desc' => $desc, |
|
| 537 | - 'table' => $desc['table'], |
|
| 538 | - 'alias' => $k, |
|
| 539 | - ); |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - return false; |
|
| 518 | + static $trouver_table = ''; |
|
| 519 | + if (!$trouver_table) { |
|
| 520 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + if (!is_array($cle)) { |
|
| 524 | + $cle = array($cle); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + foreach ($tables as $k => $table) { |
|
| 528 | + if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 529 | + if (isset($desc['field']) |
|
| 530 | + // verifier que toutes les cles cherchees sont la |
|
| 531 | + and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 532 | + // si on sait ou on veut arriver, il faut que ca colle |
|
| 533 | + and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 534 | + ) { |
|
| 535 | + return array( |
|
| 536 | + 'desc' => $desc, |
|
| 537 | + 'table' => $desc['table'], |
|
| 538 | + 'alias' => $k, |
|
| 539 | + ); |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + return false; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
@@ -567,52 +567,52 @@ discard block |
||
| 567 | 567 | */ |
| 568 | 568 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
| 569 | 569 | |
| 570 | - // support de la recherche multi champ : |
|
| 571 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 572 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 573 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 574 | - if (!is_array($cle)) { |
|
| 575 | - $cle = array($cle); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 579 | - return array($infos['table'], $infos['desc'], $cle); |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - // au premier coup, on essaye de decomposer, si possible |
|
| 583 | - if (count($cle) == 1 |
|
| 584 | - and $c = reset($cle) |
|
| 585 | - and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 586 | - ) { |
|
| 587 | - |
|
| 588 | - $desc = $boucle->show; |
|
| 589 | - |
|
| 590 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 591 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 592 | - if (isset($desc['field'][$c])) { |
|
| 593 | - $cle = array(); |
|
| 594 | - $cle[] = array_shift($decompose); // id_objet |
|
| 595 | - $cle[] = array_shift($decompose); // objet |
|
| 596 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 597 | - } |
|
| 598 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 599 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 600 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 601 | - else { |
|
| 602 | - $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 603 | - foreach ($depart as $d) { |
|
| 604 | - $cle = array(); |
|
| 605 | - $cle[] = array_shift($decompose); // id_objet |
|
| 606 | - $cle[] = array_shift($decompose); // objet |
|
| 607 | - $cle[] = $d; |
|
| 608 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 609 | - return $ext; |
|
| 610 | - } |
|
| 611 | - } |
|
| 612 | - } |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - return ""; |
|
| 570 | + // support de la recherche multi champ : |
|
| 571 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 572 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 573 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 574 | + if (!is_array($cle)) { |
|
| 575 | + $cle = array($cle); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 579 | + return array($infos['table'], $infos['desc'], $cle); |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + // au premier coup, on essaye de decomposer, si possible |
|
| 583 | + if (count($cle) == 1 |
|
| 584 | + and $c = reset($cle) |
|
| 585 | + and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 586 | + ) { |
|
| 587 | + |
|
| 588 | + $desc = $boucle->show; |
|
| 589 | + |
|
| 590 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 591 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 592 | + if (isset($desc['field'][$c])) { |
|
| 593 | + $cle = array(); |
|
| 594 | + $cle[] = array_shift($decompose); // id_objet |
|
| 595 | + $cle[] = array_shift($decompose); // objet |
|
| 596 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 597 | + } |
|
| 598 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 599 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 600 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 601 | + else { |
|
| 602 | + $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 603 | + foreach ($depart as $d) { |
|
| 604 | + $cle = array(); |
|
| 605 | + $cle[] = array_shift($decompose); // id_objet |
|
| 606 | + $cle[] = array_shift($decompose); // objet |
|
| 607 | + $cle[] = $d; |
|
| 608 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 609 | + return $ext; |
|
| 610 | + } |
|
| 611 | + } |
|
| 612 | + } |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + return ""; |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -644,21 +644,21 @@ discard block |
||
| 644 | 644 | * @return string |
| 645 | 645 | */ |
| 646 | 646 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) { |
| 647 | - if ($jointures === false) { |
|
| 648 | - $jointures = $boucle->jointures; |
|
| 649 | - } |
|
| 650 | - // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 651 | - // mais pas poour construire la jointure ensuite |
|
| 652 | - $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 653 | - if ($arrivee) { |
|
| 654 | - $desc = $boucle->show; |
|
| 655 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 656 | - $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $arrivee, '', $cond); |
|
| 657 | - if ($cle) { |
|
| 658 | - return $cle; |
|
| 659 | - } |
|
| 660 | - } |
|
| 661 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 662 | - |
|
| 663 | - return ''; |
|
| 647 | + if ($jointures === false) { |
|
| 648 | + $jointures = $boucle->jointures; |
|
| 649 | + } |
|
| 650 | + // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 651 | + // mais pas poour construire la jointure ensuite |
|
| 652 | + $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 653 | + if ($arrivee) { |
|
| 654 | + $desc = $boucle->show; |
|
| 655 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 656 | + $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $arrivee, '', $cond); |
|
| 657 | + if ($cle) { |
|
| 658 | + return $cle; |
|
| 659 | + } |
|
| 660 | + } |
|
| 661 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 662 | + |
|
| 663 | + return ''; |
|
| 664 | 664 | } |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | // sache qu'il peut enlever ce where si il enleve la jointure |
| 177 | 177 | $boucle->where["JOIN-L$n"] = |
| 178 | 178 | $echap ? |
| 179 | - array("'='","'$obj'","sql_quote('$type')") |
|
| 179 | + array("'='", "'$obj'", "sql_quote('$type')") |
|
| 180 | 180 | : |
| 181 | - array("=","$obj",sql_quote($type)); |
|
| 181 | + array("=", "$obj", sql_quote($type)); |
|
| 182 | 182 | $boucle->join["L$n"] = |
| 183 | 183 | $echap ? |
| 184 | 184 | array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
| 185 | 185 | : |
| 186 | - array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 186 | + array($id_table, $j2, $j1, "$obj=".sql_quote($type)); |
|
| 187 | 187 | } else { |
| 188 | 188 | $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
| 189 | 189 | } |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $groups = liste_champs_jointures($nom, $desc, true); |
| 217 | 217 | if (!$pk) { |
| 218 | 218 | foreach ($groups as $id_prim) { |
| 219 | - $id_field = $nom . '.' . $id_prim; |
|
| 219 | + $id_field = $nom.'.'.$id_prim; |
|
| 220 | 220 | if (!in_array($id_field, $boucle->group)) { |
| 221 | 221 | $boucle->group[] = $id_field; |
| 222 | 222 | } |
@@ -75,6 +75,9 @@ |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | +/** |
|
| 79 | + * @param string $nom |
|
| 80 | + */ |
|
| 78 | 81 | function phraser_logo_faux_filtres($nom) { |
| 79 | 82 | switch ($nom) { |
| 80 | 83 | case 'top': |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $p->etoile = '*'; |
| 54 | 54 | spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
| 55 | 55 | |
| 56 | - } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | + } elseif (preg_match("/^".NOM_DE_CHAMP.'(.*)$/sS', $nom, $m)) { |
|
| 57 | 57 | $champ = new Champ(); |
| 58 | 58 | $champ->nom_boucle = $m[2]; |
| 59 | 59 | $champ->nom_champ = $m[3]; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $p->param[0][1] = array($c); |
| 132 | 132 | $p->param[0][0] = ''; |
| 133 | 133 | $p->fonctions = array(); |
| 134 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 134 | + spip_log('FORMULAIRE_RECHERCHE avec filtre '.$c->texte, 'vieilles_defs'); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Les fonctions de ce fichier sont appelees en certains points |
@@ -25,135 +25,135 @@ discard block |
||
| 25 | 25 | // -> https://www.spip.net/fr_article901.html |
| 26 | 26 | |
| 27 | 27 | function phraser_vieux_logos(&$p) { |
| 28 | - if ($p->param[0][0]) { |
|
| 29 | - $args = array(''); |
|
| 30 | - } else { |
|
| 31 | - $args = array_shift($p->param); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - foreach ($p->param as $couple) { |
|
| 35 | - $nom = trim($couple[0]); |
|
| 36 | - if ($nom == '') { |
|
| 37 | - array_shift($p->param); |
|
| 38 | - break; |
|
| 39 | - } |
|
| 40 | - $r = phraser_logo_faux_filtres($nom); |
|
| 41 | - if ($r === 0) { |
|
| 42 | - $c = new Texte; |
|
| 43 | - $c->texte = $nom; |
|
| 44 | - $args[] = array($c); |
|
| 45 | - array_shift($p->param); |
|
| 46 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | - } elseif ($r === 2) { |
|
| 48 | - $p->etoile = '**'; |
|
| 49 | - array_shift($p->param); |
|
| 50 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | - } elseif ($r === 1) { |
|
| 52 | - array_shift($p->param); |
|
| 53 | - $p->etoile = '*'; |
|
| 54 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | - |
|
| 56 | - } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 57 | - $champ = new Champ(); |
|
| 58 | - $champ->nom_boucle = $m[2]; |
|
| 59 | - $champ->nom_champ = $m[3]; |
|
| 60 | - $champ->etoile = $m[5]; |
|
| 61 | - $champ = array($champ); |
|
| 62 | - if ($m[6]) { |
|
| 63 | - $r = new Texte; |
|
| 64 | - $r->texte = $m[6]; |
|
| 65 | - $champ[] = $r; |
|
| 66 | - } |
|
| 67 | - $args[] = $champ; |
|
| 68 | - array_shift($p->param); |
|
| 69 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 70 | - |
|
| 71 | - } // le cas else est la seule incompatibilite |
|
| 72 | - |
|
| 73 | - } |
|
| 74 | - array_unshift($p->param, $args); |
|
| 28 | + if ($p->param[0][0]) { |
|
| 29 | + $args = array(''); |
|
| 30 | + } else { |
|
| 31 | + $args = array_shift($p->param); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + foreach ($p->param as $couple) { |
|
| 35 | + $nom = trim($couple[0]); |
|
| 36 | + if ($nom == '') { |
|
| 37 | + array_shift($p->param); |
|
| 38 | + break; |
|
| 39 | + } |
|
| 40 | + $r = phraser_logo_faux_filtres($nom); |
|
| 41 | + if ($r === 0) { |
|
| 42 | + $c = new Texte; |
|
| 43 | + $c->texte = $nom; |
|
| 44 | + $args[] = array($c); |
|
| 45 | + array_shift($p->param); |
|
| 46 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | + } elseif ($r === 2) { |
|
| 48 | + $p->etoile = '**'; |
|
| 49 | + array_shift($p->param); |
|
| 50 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | + } elseif ($r === 1) { |
|
| 52 | + array_shift($p->param); |
|
| 53 | + $p->etoile = '*'; |
|
| 54 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | + |
|
| 56 | + } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 57 | + $champ = new Champ(); |
|
| 58 | + $champ->nom_boucle = $m[2]; |
|
| 59 | + $champ->nom_champ = $m[3]; |
|
| 60 | + $champ->etoile = $m[5]; |
|
| 61 | + $champ = array($champ); |
|
| 62 | + if ($m[6]) { |
|
| 63 | + $r = new Texte; |
|
| 64 | + $r->texte = $m[6]; |
|
| 65 | + $champ[] = $r; |
|
| 66 | + } |
|
| 67 | + $args[] = $champ; |
|
| 68 | + array_shift($p->param); |
|
| 69 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 70 | + |
|
| 71 | + } // le cas else est la seule incompatibilite |
|
| 72 | + |
|
| 73 | + } |
|
| 74 | + array_unshift($p->param, $args); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | function phraser_logo_faux_filtres($nom) { |
| 79 | - switch ($nom) { |
|
| 80 | - case 'top': |
|
| 81 | - case 'left': |
|
| 82 | - case 'right': |
|
| 83 | - case 'center': |
|
| 84 | - case 'bottom': |
|
| 85 | - return 0; |
|
| 86 | - case 'lien': |
|
| 87 | - return 1; |
|
| 88 | - case 'fichier': |
|
| 89 | - return 2; |
|
| 90 | - default: |
|
| 91 | - return $nom; |
|
| 92 | - } |
|
| 79 | + switch ($nom) { |
|
| 80 | + case 'top': |
|
| 81 | + case 'left': |
|
| 82 | + case 'right': |
|
| 83 | + case 'center': |
|
| 84 | + case 'bottom': |
|
| 85 | + return 0; |
|
| 86 | + case 'lien': |
|
| 87 | + return 1; |
|
| 88 | + case 'fichier': |
|
| 89 | + return 2; |
|
| 90 | + default: |
|
| 91 | + return $nom; |
|
| 92 | + } |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
| 96 | 96 | // La balise embed_document est a present le modele emb |
| 97 | 97 | |
| 98 | 98 | function phraser_vieux_emb(&$p) { |
| 99 | - if (!is_array($p->param)) { |
|
| 100 | - $p->param = array(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // Produire le premier argument {emb} |
|
| 104 | - $texte = new Texte; |
|
| 105 | - $texte->texte = 'emb'; |
|
| 106 | - $param = array('', array($texte)); |
|
| 107 | - |
|
| 108 | - // Transformer les filtres en arguments |
|
| 109 | - for ($i = 0; $i < count($p->param); $i++) { |
|
| 110 | - if ($p->param[$i][0]) { |
|
| 111 | - if (!strstr($p->param[$i][0], '=')) { |
|
| 112 | - break; |
|
| 113 | - }# on a rencontre un vrai filtre, c'est fini |
|
| 114 | - $texte = new Texte; |
|
| 115 | - $texte->texte = $p->param[$i][0]; |
|
| 116 | - $param[] = array($texte); |
|
| 117 | - } |
|
| 118 | - array_shift($p->param); |
|
| 119 | - } |
|
| 120 | - array_unshift($p->param, $param); |
|
| 121 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 122 | - $p->nom_champ = 'MODELE'; |
|
| 99 | + if (!is_array($p->param)) { |
|
| 100 | + $p->param = array(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // Produire le premier argument {emb} |
|
| 104 | + $texte = new Texte; |
|
| 105 | + $texte->texte = 'emb'; |
|
| 106 | + $param = array('', array($texte)); |
|
| 107 | + |
|
| 108 | + // Transformer les filtres en arguments |
|
| 109 | + for ($i = 0; $i < count($p->param); $i++) { |
|
| 110 | + if ($p->param[$i][0]) { |
|
| 111 | + if (!strstr($p->param[$i][0], '=')) { |
|
| 112 | + break; |
|
| 113 | + }# on a rencontre un vrai filtre, c'est fini |
|
| 114 | + $texte = new Texte; |
|
| 115 | + $texte->texte = $p->param[$i][0]; |
|
| 116 | + $param[] = array($texte); |
|
| 117 | + } |
|
| 118 | + array_shift($p->param); |
|
| 119 | + } |
|
| 120 | + array_unshift($p->param, $param); |
|
| 121 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 122 | + $p->nom_champ = 'MODELE'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // Vieux formulaire de recherch |
| 126 | 126 | |
| 127 | 127 | function phraser_vieux_recherche($p) { |
| 128 | - if ($p->param[0][0]) { |
|
| 129 | - $c = new Texte; |
|
| 130 | - $c->texte = $p->param[0][0]; |
|
| 131 | - $p->param[0][1] = array($c); |
|
| 132 | - $p->param[0][0] = ''; |
|
| 133 | - $p->fonctions = array(); |
|
| 134 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 135 | - } |
|
| 128 | + if ($p->param[0][0]) { |
|
| 129 | + $c = new Texte; |
|
| 130 | + $c->texte = $p->param[0][0]; |
|
| 131 | + $p->param[0][1] = array($c); |
|
| 132 | + $p->param[0][0] = ''; |
|
| 133 | + $p->fonctions = array(); |
|
| 134 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 135 | + } |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Gerer la notation [(#EXPOSER|on,off)] |
| 139 | 139 | function phraser_vieux_exposer($p) { |
| 140 | - if ($a = $p->fonctions) { |
|
| 141 | - preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 142 | - $args = array(); |
|
| 143 | - if ($regs[1]) { |
|
| 144 | - $a = new Texte; |
|
| 145 | - $a->texte = $regs[1]; |
|
| 146 | - $args = array('', array($a)); |
|
| 147 | - if ($regs[3]) { |
|
| 148 | - $a = new Texte; |
|
| 149 | - $a->texte = $regs[3]; |
|
| 150 | - $args[] = array($a); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - $p->param[0] = $args; |
|
| 154 | - $p->fonctions = array(); |
|
| 155 | - $p->nom_champ = 'EXPOSE'; |
|
| 156 | - } |
|
| 140 | + if ($a = $p->fonctions) { |
|
| 141 | + preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 142 | + $args = array(); |
|
| 143 | + if ($regs[1]) { |
|
| 144 | + $a = new Texte; |
|
| 145 | + $a->texte = $regs[1]; |
|
| 146 | + $args = array('', array($a)); |
|
| 147 | + if ($regs[3]) { |
|
| 148 | + $a = new Texte; |
|
| 149 | + $a->texte = $regs[3]; |
|
| 150 | + $args[] = array($a); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + $p->param[0] = $args; |
|
| 154 | + $p->fonctions = array(); |
|
| 155 | + $p->nom_champ = 'EXPOSE'; |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | function phraser_vieux_modele($p) { normaliser_args_inclumodel($p); } |
@@ -161,55 +161,55 @@ discard block |
||
| 161 | 161 | function phraser_vieux_inclu($p) { normaliser_args_inclumodel($p); } |
| 162 | 162 | |
| 163 | 163 | function normaliser_args_inclumodel($p) { |
| 164 | - $params = $p->param; |
|
| 165 | - if (!$params) { |
|
| 166 | - return; |
|
| 167 | - } |
|
| 168 | - $args = $params[0]; |
|
| 169 | - if ($args[0]) { |
|
| 170 | - return; |
|
| 171 | - } // filtre immediat |
|
| 172 | - array_shift($p->param); |
|
| 173 | - foreach ($p->param as $l) { |
|
| 174 | - if (!array_shift($l)) { |
|
| 175 | - $args = array_merge($args, $l); |
|
| 176 | - array_shift($p->param); |
|
| 177 | - } else { |
|
| 178 | - break; |
|
| 179 | - } // filtre |
|
| 180 | - } |
|
| 181 | - array_unshift($p->param, $args); |
|
| 164 | + $params = $p->param; |
|
| 165 | + if (!$params) { |
|
| 166 | + return; |
|
| 167 | + } |
|
| 168 | + $args = $params[0]; |
|
| 169 | + if ($args[0]) { |
|
| 170 | + return; |
|
| 171 | + } // filtre immediat |
|
| 172 | + array_shift($p->param); |
|
| 173 | + foreach ($p->param as $l) { |
|
| 174 | + if (!array_shift($l)) { |
|
| 175 | + $args = array_merge($args, $l); |
|
| 176 | + array_shift($p->param); |
|
| 177 | + } else { |
|
| 178 | + break; |
|
| 179 | + } // filtre |
|
| 180 | + } |
|
| 181 | + array_unshift($p->param, $args); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function normaliser_inclure($champ) { |
| 185 | - normaliser_args_inclumodel($champ); |
|
| 186 | - $l = $champ->param[0]; |
|
| 187 | - if (is_array($l) and !$l[0]) { |
|
| 188 | - foreach ($l as $k => $p) { |
|
| 189 | - if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 190 | - $p[0]->texte = trim($p[0]->texte); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - foreach ($l as $k => $p) { |
|
| 194 | - if (!$p or $p[0]->type != 'texte' or |
|
| 195 | - !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 196 | - ) { |
|
| 197 | - continue; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($r[1]) { |
|
| 201 | - $p[0]->texte = $r[1]; |
|
| 202 | - } else { |
|
| 203 | - unset($p[0]); |
|
| 204 | - } |
|
| 205 | - $champ->texte = $p; |
|
| 206 | - unset($champ->param[0][$k]); |
|
| 207 | - if (count($champ->param[0]) == 1) { |
|
| 208 | - array_shift($champ->param); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - spip_log("inclure sans fond ni fichier"); |
|
| 185 | + normaliser_args_inclumodel($champ); |
|
| 186 | + $l = $champ->param[0]; |
|
| 187 | + if (is_array($l) and !$l[0]) { |
|
| 188 | + foreach ($l as $k => $p) { |
|
| 189 | + if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 190 | + $p[0]->texte = trim($p[0]->texte); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + foreach ($l as $k => $p) { |
|
| 194 | + if (!$p or $p[0]->type != 'texte' or |
|
| 195 | + !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 196 | + ) { |
|
| 197 | + continue; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($r[1]) { |
|
| 201 | + $p[0]->texte = $r[1]; |
|
| 202 | + } else { |
|
| 203 | + unset($p[0]); |
|
| 204 | + } |
|
| 205 | + $champ->texte = $p; |
|
| 206 | + unset($champ->param[0][$k]); |
|
| 207 | + if (count($champ->param[0]) == 1) { |
|
| 208 | + array_shift($champ->param); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + spip_log("inclure sans fond ni fichier"); |
|
| 215 | 215 | } |
@@ -231,7 +231,7 @@ |
||
| 231 | 231 | * |
| 232 | 232 | * @uses public_tester_redirection_dist() |
| 233 | 233 | * @param string $fond |
| 234 | - * @param array $contexte |
|
| 234 | + * @param string $contexte |
|
| 235 | 235 | * @param string $connect |
| 236 | 236 | * @return array|bool |
| 237 | 237 | */ |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_fichiers_fonctions(); |
@@ -31,177 +31,177 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | // https://code.spip.net/@public_parametrer_dist |
| 33 | 33 | function public_parametrer_dist($fond, $contexte = '', $cache = '', $connect = '') { |
| 34 | - static $composer, $styliser, $notes = null; |
|
| 35 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | - if ($page) { |
|
| 37 | - return $page; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - if (isset($contexte['lang'])) { |
|
| 41 | - $lang = $contexte['lang']; |
|
| 42 | - } elseif (!isset($lang)) { |
|
| 43 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | - if ($select) { |
|
| 48 | - $select = lang_select($lang); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | - |
|
| 53 | - if (!$styliser) { |
|
| 54 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | - } |
|
| 56 | - list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | - |
|
| 59 | - if ($skel) { |
|
| 60 | - |
|
| 61 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 62 | - // (recursion possible a cause des modeles) |
|
| 63 | - if ($debug) { |
|
| 64 | - $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 65 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // charger le squelette en specifiant les langages cibles et source |
|
| 69 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 70 | - |
|
| 71 | - if (!$composer) { |
|
| 72 | - $composer = charger_fonction('composer', 'public'); |
|
| 73 | - } |
|
| 74 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 75 | - } else { |
|
| 76 | - $fonc = ''; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 80 | - $page = $fonc; |
|
| 81 | - } else { |
|
| 82 | - // Preparer l'appel de la fonction principale du squelette |
|
| 83 | - |
|
| 84 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 85 | - |
|
| 86 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 87 | - // et on enregistre l'etat courant des globales de notes... |
|
| 88 | - if (is_null($notes)) { |
|
| 89 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 90 | - } |
|
| 91 | - if ($notes) { |
|
| 92 | - $notes('', 'empiler'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - // Rajouter d'office ces deux parametres |
|
| 96 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 97 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 98 | - if (!isset($contexte['date'])) { |
|
| 99 | - $contexte['date'] = date("Y-m-d H:i:s"); |
|
| 100 | - $contexte['date_default'] = true; |
|
| 101 | - } else { |
|
| 102 | - $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - if (!isset($contexte['date_redac'])) { |
|
| 106 | - $contexte['date_redac'] = date("Y-m-d H:i:s"); |
|
| 107 | - $contexte['date_redac_default'] = true; |
|
| 108 | - } else { |
|
| 109 | - $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 113 | - try { |
|
| 114 | - $page = $fonc(array('cache' => $cache), array($contexte)); |
|
| 115 | - } catch (Throwable $e) { |
|
| 116 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 117 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 118 | - $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 119 | - $corps = "<pre>$msg</pre>"; |
|
| 120 | - $page = analyse_resultat_skel($fond, array('cache' => $cache), $corps, $sourcefile); |
|
| 121 | - erreur_squelette($full_msg); |
|
| 122 | - unset($msg, $full_msg, $corps); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 126 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 127 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 128 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 129 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 130 | - if ($notes) { |
|
| 131 | - $notes('', 'depiler'); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // reinjecter en dynamique la pile des notes |
|
| 135 | - // si il y a des inclure dynamiques |
|
| 136 | - // si la pile n'est pas vide |
|
| 137 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 138 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 139 | - if ($notes) { |
|
| 140 | - $page['notes'] = $notes('', 'sauver_etat'); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // spip_log: un joli contexte |
|
| 144 | - $infos = presenter_contexte(array_filter($contexte)); |
|
| 145 | - |
|
| 146 | - $profile = spip_timer($a); |
|
| 147 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 148 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 149 | - |
|
| 150 | - if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 151 | - spip_log("calcul ($profile) [$skel] $infos" |
|
| 152 | - .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - if ($debug) { |
|
| 156 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 157 | - $t = strlen($page['texte']) ? $page['texte'] : " "; |
|
| 158 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 159 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 160 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 161 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | - and (_request('var_mode_objet') == $fonc) |
|
| 163 | - and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | - ) { |
|
| 165 | - erreur_squelette(); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | - if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | - // si aucun #CACHE{} spécifié |
|
| 172 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | - // entre public et prive |
|
| 174 | - if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | - } else { |
|
| 177 | - $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $page['contexte'] = $contexte; |
|
| 182 | - |
|
| 183 | - // faire remonter le fichier source |
|
| 184 | - static $js_inclus = false; |
|
| 185 | - if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | - $page['sourcefile'] = $sourcefile; |
|
| 187 | - $page['texte'] = |
|
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 189 | - . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | - $js_inclus = true; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | - unset($GLOBALS['cache_utilise_session']); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($select) { |
|
| 201 | - lang_select(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return $page; |
|
| 34 | + static $composer, $styliser, $notes = null; |
|
| 35 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 36 | + if ($page) { |
|
| 37 | + return $page; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + if (isset($contexte['lang'])) { |
|
| 41 | + $lang = $contexte['lang']; |
|
| 42 | + } elseif (!isset($lang)) { |
|
| 43 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 47 | + if ($select) { |
|
| 48 | + $select = lang_select($lang); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 52 | + |
|
| 53 | + if (!$styliser) { |
|
| 54 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 55 | + } |
|
| 56 | + list($skel, $mime_type, $gram, $sourcefile) = |
|
| 57 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 58 | + |
|
| 59 | + if ($skel) { |
|
| 60 | + |
|
| 61 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 62 | + // (recursion possible a cause des modeles) |
|
| 63 | + if ($debug) { |
|
| 64 | + $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 65 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // charger le squelette en specifiant les langages cibles et source |
|
| 69 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 70 | + |
|
| 71 | + if (!$composer) { |
|
| 72 | + $composer = charger_fonction('composer', 'public'); |
|
| 73 | + } |
|
| 74 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 75 | + } else { |
|
| 76 | + $fonc = ''; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 80 | + $page = $fonc; |
|
| 81 | + } else { |
|
| 82 | + // Preparer l'appel de la fonction principale du squelette |
|
| 83 | + |
|
| 84 | + spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 85 | + |
|
| 86 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 87 | + // et on enregistre l'etat courant des globales de notes... |
|
| 88 | + if (is_null($notes)) { |
|
| 89 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 90 | + } |
|
| 91 | + if ($notes) { |
|
| 92 | + $notes('', 'empiler'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + // Rajouter d'office ces deux parametres |
|
| 96 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 97 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 98 | + if (!isset($contexte['date'])) { |
|
| 99 | + $contexte['date'] = date("Y-m-d H:i:s"); |
|
| 100 | + $contexte['date_default'] = true; |
|
| 101 | + } else { |
|
| 102 | + $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + if (!isset($contexte['date_redac'])) { |
|
| 106 | + $contexte['date_redac'] = date("Y-m-d H:i:s"); |
|
| 107 | + $contexte['date_redac_default'] = true; |
|
| 108 | + } else { |
|
| 109 | + $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 113 | + try { |
|
| 114 | + $page = $fonc(array('cache' => $cache), array($contexte)); |
|
| 115 | + } catch (Throwable $e) { |
|
| 116 | + $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 117 | + $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 118 | + $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
|
| 119 | + $corps = "<pre>$msg</pre>"; |
|
| 120 | + $page = analyse_resultat_skel($fond, array('cache' => $cache), $corps, $sourcefile); |
|
| 121 | + erreur_squelette($full_msg); |
|
| 122 | + unset($msg, $full_msg, $corps); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 126 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 127 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 128 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 129 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 130 | + if ($notes) { |
|
| 131 | + $notes('', 'depiler'); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // reinjecter en dynamique la pile des notes |
|
| 135 | + // si il y a des inclure dynamiques |
|
| 136 | + // si la pile n'est pas vide |
|
| 137 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 138 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 139 | + if ($notes) { |
|
| 140 | + $page['notes'] = $notes('', 'sauver_etat'); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // spip_log: un joli contexte |
|
| 144 | + $infos = presenter_contexte(array_filter($contexte)); |
|
| 145 | + |
|
| 146 | + $profile = spip_timer($a); |
|
| 147 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 148 | + . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 149 | + |
|
| 150 | + if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 151 | + spip_log("calcul ($profile) [$skel] $infos" |
|
| 152 | + .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if ($debug) { |
|
| 156 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 157 | + $t = strlen($page['texte']) ? $page['texte'] : " "; |
|
| 158 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 159 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 160 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 161 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 162 | + and (_request('var_mode_objet') == $fonc) |
|
| 163 | + and (_request('var_mode_affiche') == 'resultat') |
|
| 164 | + ) { |
|
| 165 | + erreur_squelette(); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 169 | + if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 170 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 171 | + // si aucun #CACHE{} spécifié |
|
| 172 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 173 | + // entre public et prive |
|
| 174 | + if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 175 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 176 | + } else { |
|
| 177 | + $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $page['contexte'] = $contexte; |
|
| 182 | + |
|
| 183 | + // faire remonter le fichier source |
|
| 184 | + static $js_inclus = false; |
|
| 185 | + if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 186 | + $page['sourcefile'] = $sourcefile; |
|
| 187 | + $page['texte'] = |
|
| 188 | + "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 189 | + . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 190 | + $js_inclus = true; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 194 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 195 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 196 | + unset($GLOBALS['cache_utilise_session']); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($select) { |
|
| 201 | + lang_select(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return $page; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -210,33 +210,33 @@ discard block |
||
| 210 | 210 | * @return string |
| 211 | 211 | */ |
| 212 | 212 | function presenter_contexte($contexte, $profondeur_max = 1, $max_lines = 0) { |
| 213 | - $infos = array(); |
|
| 214 | - $line = 0; |
|
| 215 | - foreach ($contexte as $var => $val) { |
|
| 216 | - $line++; |
|
| 217 | - if ($max_lines and $max_lines < $line) { |
|
| 218 | - $infos[] = '…'; |
|
| 219 | - break; |
|
| 220 | - } |
|
| 221 | - if (is_array($val)) { |
|
| 222 | - if ($profondeur_max > 0) { |
|
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | - } else { |
|
| 225 | - $val = 'array:' . count($val); |
|
| 226 | - } |
|
| 227 | - } elseif (is_object($val)) { |
|
| 228 | - $val = get_class($val); |
|
| 229 | - } elseif (strlen("$val") > 30) { |
|
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 231 | - if (strstr($val, ' ')) { |
|
| 232 | - $val = "'$val'"; |
|
| 233 | - } |
|
| 234 | - } elseif (strstr($val, ' ')) { |
|
| 235 | - $val = "'$val'"; |
|
| 236 | - } |
|
| 237 | - $infos[] = $var . '=' . $val; |
|
| 238 | - } |
|
| 239 | - return join(', ', $infos); |
|
| 213 | + $infos = array(); |
|
| 214 | + $line = 0; |
|
| 215 | + foreach ($contexte as $var => $val) { |
|
| 216 | + $line++; |
|
| 217 | + if ($max_lines and $max_lines < $line) { |
|
| 218 | + $infos[] = '…'; |
|
| 219 | + break; |
|
| 220 | + } |
|
| 221 | + if (is_array($val)) { |
|
| 222 | + if ($profondeur_max > 0) { |
|
| 223 | + $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 224 | + } else { |
|
| 225 | + $val = 'array:' . count($val); |
|
| 226 | + } |
|
| 227 | + } elseif (is_object($val)) { |
|
| 228 | + $val = get_class($val); |
|
| 229 | + } elseif (strlen("$val") > 30) { |
|
| 230 | + $val = substr("$val", 0, 29) . '…'; |
|
| 231 | + if (strstr($val, ' ')) { |
|
| 232 | + $val = "'$val'"; |
|
| 233 | + } |
|
| 234 | + } elseif (strstr($val, ' ')) { |
|
| 235 | + $val = "'$val'"; |
|
| 236 | + } |
|
| 237 | + $infos[] = $var . '=' . $val; |
|
| 238 | + } |
|
| 239 | + return join(', ', $infos); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | |
@@ -253,11 +253,11 @@ discard block |
||
| 253 | 253 | * @return array|bool |
| 254 | 254 | */ |
| 255 | 255 | function tester_redirection($fond, $contexte, $connect) { |
| 256 | - static $tester_redirection = null; |
|
| 257 | - if (is_null($tester_redirection)) { |
|
| 258 | - $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 259 | - } |
|
| 260 | - return $tester_redirection($fond, $contexte, $connect); |
|
| 256 | + static $tester_redirection = null; |
|
| 257 | + if (is_null($tester_redirection)) { |
|
| 258 | + $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 259 | + } |
|
| 260 | + return $tester_redirection($fond, $contexte, $connect); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | |
@@ -273,41 +273,41 @@ discard block |
||
| 273 | 273 | * @return array|bool |
| 274 | 274 | */ |
| 275 | 275 | function public_tester_redirection_dist($fond, $contexte, $connect) { |
| 276 | - if ($fond == 'article' |
|
| 277 | - and !empty($contexte['id_article']) |
|
| 278 | - and $id_article = intval($contexte['id_article']) |
|
| 279 | - ) { |
|
| 280 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 281 | - $m = quete_virtuel($id_article, $connect); |
|
| 282 | - if (strlen($m)) { |
|
| 283 | - include_spip('inc/texte'); |
|
| 284 | - // les navigateurs pataugent si l'URL est vide |
|
| 285 | - if ($url = virtuel_redirige($m, true)) { |
|
| 286 | - // passer en url absolue car cette redirection pourra |
|
| 287 | - // etre utilisee dans un contexte d'url qui change |
|
| 288 | - // y compris url arbo |
|
| 289 | - $status = 302; |
|
| 290 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 291 | - $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 292 | - } |
|
| 293 | - if (!preg_match(',^\w+:,', $url)) { |
|
| 294 | - include_spip('inc/filtres_mini'); |
|
| 295 | - $url = url_absolue($url); |
|
| 296 | - } |
|
| 297 | - $url = str_replace('&', '&', $url); |
|
| 298 | - |
|
| 299 | - return array( |
|
| 300 | - 'texte' => "<" |
|
| 301 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 302 | - . texte_script($url) |
|
| 303 | - . "','',$status);" |
|
| 304 | - . "?" . ">", |
|
| 305 | - 'process_ins' => 'php', |
|
| 306 | - 'status' => $status |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - return false; |
|
| 276 | + if ($fond == 'article' |
|
| 277 | + and !empty($contexte['id_article']) |
|
| 278 | + and $id_article = intval($contexte['id_article']) |
|
| 279 | + ) { |
|
| 280 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 281 | + $m = quete_virtuel($id_article, $connect); |
|
| 282 | + if (strlen($m)) { |
|
| 283 | + include_spip('inc/texte'); |
|
| 284 | + // les navigateurs pataugent si l'URL est vide |
|
| 285 | + if ($url = virtuel_redirige($m, true)) { |
|
| 286 | + // passer en url absolue car cette redirection pourra |
|
| 287 | + // etre utilisee dans un contexte d'url qui change |
|
| 288 | + // y compris url arbo |
|
| 289 | + $status = 302; |
|
| 290 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 291 | + $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 292 | + } |
|
| 293 | + if (!preg_match(',^\w+:,', $url)) { |
|
| 294 | + include_spip('inc/filtres_mini'); |
|
| 295 | + $url = url_absolue($url); |
|
| 296 | + } |
|
| 297 | + $url = str_replace('&', '&', $url); |
|
| 298 | + |
|
| 299 | + return array( |
|
| 300 | + 'texte' => "<" |
|
| 301 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 302 | + . texte_script($url) |
|
| 303 | + . "','',$status);" |
|
| 304 | + . "?" . ">", |
|
| 305 | + 'process_ins' => 'php', |
|
| 306 | + 'status' => $status |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + return false; |
|
| 313 | 313 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | } else { |
| 82 | 82 | // Preparer l'appel de la fonction principale du squelette |
| 83 | 83 | |
| 84 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 84 | + spip_timer($a = 'calcul page '.rand(0, 1000)); |
|
| 85 | 85 | |
| 86 | 86 | // On cree un marqueur de notes unique lie a cette composition |
| 87 | 87 | // et on enregistre l'etat courant des globales de notes... |
@@ -113,8 +113,8 @@ discard block |
||
| 113 | 113 | try { |
| 114 | 114 | $page = $fonc(array('cache' => $cache), array($contexte)); |
| 115 | 115 | } catch (Throwable $e) { |
| 116 | - $msg = _T('zbug_erreur_execution_page') . " $sourcefile"; |
|
| 117 | - $full_msg = $msg . ' | File ' . $e->getFile() . ' Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 116 | + $msg = _T('zbug_erreur_execution_page')." $sourcefile"; |
|
| 117 | + $full_msg = $msg.' | File '.$e->getFile().' Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 118 | 118 | $full_msg = str_replace(_ROOT_RACINE, '[…]/', $full_msg); |
| 119 | 119 | $corps = "<pre>$msg</pre>"; |
| 120 | 120 | $page = analyse_resultat_skel($fond, array('cache' => $cache), $corps, $sourcefile); |
@@ -145,17 +145,17 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | $profile = spip_timer($a); |
| 147 | 147 | spip_log("calcul ($profile) [$skel] $infos" |
| 148 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 148 | + . ' ('.strlen($page['texte']).' octets)'); |
|
| 149 | 149 | |
| 150 | - if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 150 | + if (defined('_CALCUL_PROFILER') AND intval($profile) > _CALCUL_PROFILER) { |
|
| 151 | 151 | spip_log("calcul ($profile) [$skel] $infos" |
| 152 | - .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 152 | + .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'], "profiler"._LOG_AVERTISSEMENT); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | if ($debug) { |
| 156 | 156 | // si c'est ce que demande le debusqueur, lui passer la main |
| 157 | 157 | $t = strlen($page['texte']) ? $page['texte'] : " "; |
| 158 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 158 | + $GLOBALS['debug_objets']['resultat'][$fonc.'tout'] = $t; |
|
| 159 | 159 | $GLOBALS['debug_objets']['courant'] = $courant; |
| 160 | 160 | $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
| 161 | 161 | if ($GLOBALS['debug_objets']['sourcefile'] |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
| 186 | 186 | $page['sourcefile'] = $sourcefile; |
| 187 | 187 | $page['texte'] = |
| 188 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 188 | + "<div class='inclure_blocs'><h6>".$page['sourcefile']."</h6>".$page['texte']."</div>" |
|
| 189 | 189 | . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
| 190 | 190 | $js_inclus = true; |
| 191 | 191 | } |
@@ -220,21 +220,21 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | if (is_array($val)) { |
| 222 | 222 | if ($profondeur_max > 0) { |
| 223 | - $val = 'array:' . count($val) . '(' . presenter_contexte($val, $profondeur_max - 1, 3) . ')'; |
|
| 223 | + $val = 'array:'.count($val).'('.presenter_contexte($val, $profondeur_max - 1, 3).')'; |
|
| 224 | 224 | } else { |
| 225 | - $val = 'array:' . count($val); |
|
| 225 | + $val = 'array:'.count($val); |
|
| 226 | 226 | } |
| 227 | 227 | } elseif (is_object($val)) { |
| 228 | 228 | $val = get_class($val); |
| 229 | 229 | } elseif (strlen("$val") > 30) { |
| 230 | - $val = substr("$val", 0, 29) . '…'; |
|
| 230 | + $val = substr("$val", 0, 29).'…'; |
|
| 231 | 231 | if (strstr($val, ' ')) { |
| 232 | 232 | $val = "'$val'"; |
| 233 | 233 | } |
| 234 | 234 | } elseif (strstr($val, ' ')) { |
| 235 | 235 | $val = "'$val'"; |
| 236 | 236 | } |
| 237 | - $infos[] = $var . '=' . $val; |
|
| 237 | + $infos[] = $var.'='.$val; |
|
| 238 | 238 | } |
| 239 | 239 | return join(', ', $infos); |
| 240 | 240 | } |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | . "?php include_spip('inc/headers');redirige_par_entete('" |
| 302 | 302 | . texte_script($url) |
| 303 | 303 | . "','',$status);" |
| 304 | - . "?" . ">", |
|
| 304 | + . "?".">", |
|
| 305 | 305 | 'process_ins' => 'php', |
| 306 | 306 | 'status' => $status |
| 307 | 307 | ); |
@@ -158,7 +158,7 @@ |
||
| 158 | 158 | * @param string $corps |
| 159 | 159 | * @param array $filtres |
| 160 | 160 | * Tableau de filtres à appliquer. |
| 161 | - * @return mixed|string |
|
| 161 | + * @return string |
|
| 162 | 162 | */ |
| 163 | 163 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 164 | 164 | $series_filtres = func_get_args(); |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * Texte |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_texte($texte, &$p) { |
| 44 | - $code = "'" . str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte) . "'"; |
|
| 44 | + $code = "'" . str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte) . "'"; |
|
| 45 | 45 | |
| 46 | - return $code; |
|
| 46 | + return $code; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | |
@@ -59,43 +59,43 @@ discard block |
||
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | 61 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite=1000) : string { |
| 62 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 69 | - |
|
| 70 | - // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 71 | - // proto: filtre_set(&$Pile, $val, $args...) |
|
| 72 | - if (strpbrk($f, ':')) { // Class::method |
|
| 73 | - $refl = new ReflectionMethod($f); |
|
| 74 | - } else { |
|
| 75 | - $refl = new ReflectionFunction($f); |
|
| 76 | - } |
|
| 77 | - $refs = $refl->getParameters(); |
|
| 78 | - if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 79 | - $code = "$f(\$Pile,$code$arglist)"; |
|
| 80 | - $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 81 | - } else { |
|
| 82 | - $code = "$f($code$arglist)"; |
|
| 83 | - $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 84 | - } |
|
| 85 | - $nb_args_f = $nb_arg_gauche+$nb_arg_droite; |
|
| 86 | - $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 87 | - if (($nb_args_f < $min_f)) { |
|
| 88 | - $msg_args = ['filtre' => texte_script ($fonc), 'nb'=> $min_f - $nb_args_f]; |
|
| 89 | - erreur_squelette ([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - // le filtre n'existe pas, |
|
| 93 | - // on le notifie |
|
| 94 | - else { |
|
| 95 | - erreur_squelette(array('zbug_erreur_filtre', array('filtre' => texte_script($fonc))), $p); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return $code; |
|
| 62 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 69 | + |
|
| 70 | + // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 71 | + // proto: filtre_set(&$Pile, $val, $args...) |
|
| 72 | + if (strpbrk($f, ':')) { // Class::method |
|
| 73 | + $refl = new ReflectionMethod($f); |
|
| 74 | + } else { |
|
| 75 | + $refl = new ReflectionFunction($f); |
|
| 76 | + } |
|
| 77 | + $refs = $refl->getParameters(); |
|
| 78 | + if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 79 | + $code = "$f(\$Pile,$code$arglist)"; |
|
| 80 | + $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 81 | + } else { |
|
| 82 | + $code = "$f($code$arglist)"; |
|
| 83 | + $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 84 | + } |
|
| 85 | + $nb_args_f = $nb_arg_gauche+$nb_arg_droite; |
|
| 86 | + $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 87 | + if (($nb_args_f < $min_f)) { |
|
| 88 | + $msg_args = ['filtre' => texte_script ($fonc), 'nb'=> $min_f - $nb_args_f]; |
|
| 89 | + erreur_squelette ([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + // le filtre n'existe pas, |
|
| 93 | + // on le notifie |
|
| 94 | + else { |
|
| 95 | + erreur_squelette(array('zbug_erreur_filtre', array('filtre' => texte_script($fonc))), $p); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return $code; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Calculer un <INCLURE(xx.php)> |
@@ -119,15 +119,15 @@ discard block |
||
| 119 | 119 | * @return string |
| 120 | 120 | */ |
| 121 | 121 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
| 122 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 123 | - // si inexistant, on essaiera a l'execution |
|
| 124 | - if ($path = find_in_path($fichier)) { |
|
| 125 | - $path = "\"$path\""; |
|
| 126 | - } else { |
|
| 127 | - $path = "find_in_path(\"$fichier\")"; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 122 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 123 | + // si inexistant, on essaiera a l'execution |
|
| 124 | + if ($path = find_in_path($fichier)) { |
|
| 125 | + $path = "\"$path\""; |
|
| 126 | + } else { |
|
| 127 | + $path = "find_in_path(\"$fichier\")"; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -139,19 +139,19 @@ discard block |
||
| 139 | 139 | * @return string |
| 140 | 140 | */ |
| 141 | 141 | function sandbox_composer_interdire_scripts($code, &$p) { |
| 142 | - // Securite |
|
| 143 | - if ($p->interdire_scripts |
|
| 144 | - and $p->etoile != '**' |
|
| 145 | - ) { |
|
| 146 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 147 | - $code = "interdire_scripts($code)"; |
|
| 148 | - } else { |
|
| 149 | - $code = interdire_scripts($r[2]); |
|
| 150 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return $code; |
|
| 142 | + // Securite |
|
| 143 | + if ($p->interdire_scripts |
|
| 144 | + and $p->etoile != '**' |
|
| 145 | + ) { |
|
| 146 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 147 | + $code = "interdire_scripts($code)"; |
|
| 148 | + } else { |
|
| 149 | + $code = interdire_scripts($r[2]); |
|
| 150 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return $code; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | |
@@ -170,30 +170,30 @@ discard block |
||
| 170 | 170 | * @return mixed|string |
| 171 | 171 | */ |
| 172 | 172 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 173 | - $series_filtres = func_get_args(); |
|
| 174 | - array_shift($series_filtres);// skel |
|
| 175 | - array_shift($series_filtres);// corps |
|
| 176 | - |
|
| 177 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 178 | - if ($skel['process_ins'] == 'php') { |
|
| 179 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - // recuperer les couples de remplacement |
|
| 183 | - $replace = echapper_php_callback(); |
|
| 184 | - |
|
| 185 | - foreach ($series_filtres as $filtres) { |
|
| 186 | - if (count($filtres)) { |
|
| 187 | - foreach ($filtres as $filtre) { |
|
| 188 | - if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 189 | - $corps = $f($corps); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - // restaurer les echappements |
|
| 196 | - return str_replace($replace[0], $replace[1], $corps); |
|
| 173 | + $series_filtres = func_get_args(); |
|
| 174 | + array_shift($series_filtres);// skel |
|
| 175 | + array_shift($series_filtres);// corps |
|
| 176 | + |
|
| 177 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 178 | + if ($skel['process_ins'] == 'php') { |
|
| 179 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + // recuperer les couples de remplacement |
|
| 183 | + $replace = echapper_php_callback(); |
|
| 184 | + |
|
| 185 | + foreach ($series_filtres as $filtres) { |
|
| 186 | + if (count($filtres)) { |
|
| 187 | + foreach ($filtres as $filtre) { |
|
| 188 | + if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 189 | + $corps = $f($corps); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + // restaurer les echappements |
|
| 196 | + return str_replace($replace[0], $replace[1], $corps); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -212,21 +212,21 @@ discard block |
||
| 212 | 212 | * - array : Liste( liste des codes PHP, liste des substitutions ) |
| 213 | 213 | **/ |
| 214 | 214 | function echapper_php_callback($r = null) { |
| 215 | - static $src = array(); |
|
| 216 | - static $dst = array(); |
|
| 215 | + static $src = array(); |
|
| 216 | + static $dst = array(); |
|
| 217 | 217 | |
| 218 | - // si on recoit un tableau, on est en mode echappement |
|
| 219 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 220 | - if (is_array($r)) { |
|
| 221 | - $dst[] = $r[0]; |
|
| 218 | + // si on recoit un tableau, on est en mode echappement |
|
| 219 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 220 | + if (is_array($r)) { |
|
| 221 | + $dst[] = $r[0]; |
|
| 222 | 222 | |
| 223 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 224 | - } |
|
| 223 | + return $src[] = '___' . md5($r[0]) . '___'; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 227 | - // et on RAZ les remplacements |
|
| 228 | - $r = array($src, $dst); |
|
| 229 | - $src = $dst = array(); |
|
| 226 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 227 | + // et on RAZ les remplacements |
|
| 228 | + $r = array($src, $dst); |
|
| 229 | + $src = $dst = array(); |
|
| 230 | 230 | |
| 231 | - return $r; |
|
| 231 | + return $r; |
|
| 232 | 232 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * Texte |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_texte($texte, &$p) { |
| 44 | - $code = "'" . str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte) . "'"; |
|
| 44 | + $code = "'".str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte)."'"; |
|
| 45 | 45 | |
| 46 | 46 | return $code; |
| 47 | 47 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * Balise qui appelle ce filtre |
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | -function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite=1000) : string { |
|
| 61 | +function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000) : string { |
|
| 62 | 62 | if (isset($GLOBALS['spip_matrice'][$fonc])) { |
| 63 | 63 | $code = "filtrer('$fonc',$code$arglist)"; |
| 64 | 64 | } |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | $code = "$f($code$arglist)"; |
| 83 | 83 | $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
| 84 | 84 | } |
| 85 | - $nb_args_f = $nb_arg_gauche+$nb_arg_droite; |
|
| 85 | + $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 86 | 86 | $min_f = $refl->getNumberOfRequiredParameters(); |
| 87 | 87 | if (($nb_args_f < $min_f)) { |
| 88 | - $msg_args = ['filtre' => texte_script ($fonc), 'nb'=> $min_f - $nb_args_f]; |
|
| 89 | - erreur_squelette ([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 88 | + $msg_args = ['filtre' => texte_script($fonc), 'nb'=> $min_f - $nb_args_f]; |
|
| 89 | + erreur_squelette(['zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | // le filtre n'existe pas, |
@@ -171,8 +171,8 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 173 | 173 | $series_filtres = func_get_args(); |
| 174 | - array_shift($series_filtres);// skel |
|
| 175 | - array_shift($series_filtres);// corps |
|
| 174 | + array_shift($series_filtres); // skel |
|
| 175 | + array_shift($series_filtres); // corps |
|
| 176 | 176 | |
| 177 | 177 | // proteger les <INCLUDE> et tous les morceaux de php licites |
| 178 | 178 | if ($skel['process_ins'] == 'php') { |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | if (is_array($r)) { |
| 221 | 221 | $dst[] = $r[0]; |
| 222 | 222 | |
| 223 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 223 | + return $src[] = '___'.md5($r[0]).'___'; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // si on recoit pas un tableau, on renvoit les couples de substitution |
@@ -236,7 +236,7 @@ |
||
| 236 | 236 | * @param string $type |
| 237 | 237 | * @param string $ext |
| 238 | 238 | * @param bool $echafauder |
| 239 | - * @return mixed |
|
| 239 | + * @return string|boolean |
|
| 240 | 240 | */ |
| 241 | 241 | function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) { |
| 242 | 242 | if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @package SPIP\Core\Public\Styliser |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined("_ECRIRE_INC_VERSION")) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -29,181 +29,181 @@ discard block |
||
| 29 | 29 | * @return array Données modifiées du pipeline |
| 30 | 30 | */ |
| 31 | 31 | function public_styliser_par_z_dist($flux) { |
| 32 | - static $prefix_path = null; |
|
| 33 | - static $prefix_length; |
|
| 34 | - static $z_blocs; |
|
| 35 | - static $apl_constant; |
|
| 36 | - static $page; |
|
| 37 | - static $disponible = array(); |
|
| 38 | - static $echafauder; |
|
| 39 | - static $prepend = ""; |
|
| 40 | - |
|
| 41 | - if (!isset($prefix_path)) { |
|
| 42 | - $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | - if (test_espace_prive()) { |
|
| 44 | - $prefix_path = "prive/squelettes/"; |
|
| 45 | - $prefix_length = strlen($prefix_path); |
|
| 46 | - $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | - $page = 'exec'; |
|
| 48 | - $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | - define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | - } else { |
|
| 51 | - $prefix_path = ""; |
|
| 52 | - $prefix_length = 0; |
|
| 53 | - $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | - $page = _SPIP_PAGE; |
|
| 55 | - $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(_DIR_PLUGIN_DIST, |
|
| 57 | - '/') : '')); |
|
| 58 | - } |
|
| 59 | - $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ""); |
|
| 60 | - } |
|
| 61 | - $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 62 | - |
|
| 63 | - $fond = $flux['args']['fond']; |
|
| 64 | - |
|
| 65 | - if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 66 | - $fond = substr($fond, $prefix_length); |
|
| 67 | - $squelette = $flux['data']; |
|
| 68 | - $ext = $flux['args']['ext']; |
|
| 69 | - // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 70 | - if (defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 71 | - and $dir = explode('/', $fond) |
|
| 72 | - and count($dir) == 2 // pas un sous repertoire |
|
| 73 | - and $dir = reset($dir) |
|
| 74 | - and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 75 | - and defined($apl_constant) |
|
| 76 | - and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 77 | - and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 78 | - ) { |
|
| 79 | - $flux['data'] = $pipe; |
|
| 80 | - |
|
| 81 | - return $flux; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 85 | - if ($squelette and !z_fond_valide($squelette)) { |
|
| 86 | - $squelette = ""; |
|
| 87 | - $echafauder = ""; |
|
| 88 | - } |
|
| 89 | - if ($prepend) { |
|
| 90 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 91 | - if ($squelette) { |
|
| 92 | - $flux['data'] = $squelette; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // gerer les squelettes non trouves |
|
| 97 | - // -> router vers les /dist.html |
|
| 98 | - // ou scaffolding ou page automatique les contenus |
|
| 99 | - if (!$squelette) { |
|
| 100 | - |
|
| 101 | - // si on est sur un ?page=XX non trouve |
|
| 102 | - if ((isset($flux['args']['contexte'][$page]) |
|
| 103 | - and $flux['args']['contexte'][$page] == $fond) |
|
| 104 | - or (isset($flux['args']['contexte']['type-page']) |
|
| 105 | - and $flux['args']['contexte']['type-page'] == $fond) |
|
| 106 | - or ($fond == 'sommaire' |
|
| 107 | - and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 108 | - ) { |
|
| 109 | - |
|
| 110 | - // si on est sur un ?page=XX non trouve |
|
| 111 | - // se brancher sur contenu/xx si il existe |
|
| 112 | - // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 113 | - if (!isset($disponible[$fond])) { |
|
| 114 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if ($disponible[$fond]) { |
|
| 118 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // echafaudage : |
|
| 123 | - // si c'est un fond de contenu d'un objet en base |
|
| 124 | - // generer un fond automatique a la volee pour les webmestres |
|
| 125 | - elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 126 | - $type = substr($fond, strlen($z_contenu) + 1); |
|
| 127 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 128 | - $type = $flux['args']['contexte'][$page]; |
|
| 129 | - } |
|
| 130 | - if (!isset($disponible[$type])) { |
|
| 131 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 132 | - } |
|
| 133 | - if (is_string($disponible[$type])) { |
|
| 134 | - $flux['data'] = $disponible[$type]; |
|
| 135 | - } elseif ($echafauder |
|
| 136 | - and include_spip('inc/autoriser') |
|
| 137 | - and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 138 | - and autoriser('echafauder', $type) |
|
| 139 | - and $is = $disponible[$type] |
|
| 140 | - and is_array($is) |
|
| 141 | - ) { |
|
| 142 | - $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 143 | - } else { |
|
| 144 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, '404', $ext, |
|
| 145 | - $echafauder)); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 150 | - // et si il y a bien un contenu correspondant ou echafaudable |
|
| 151 | - // se rabbatre sur le dist.html du bloc concerne |
|
| 152 | - else { |
|
| 153 | - if ($dir = explode('/', $fond) |
|
| 154 | - and $dir = reset($dir) |
|
| 155 | - and $dir !== $z_contenu |
|
| 156 | - and in_array($dir, $z_blocs) |
|
| 157 | - ) { |
|
| 158 | - $type = substr($fond, strlen("$dir/")); |
|
| 159 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 160 | - $type = $flux['args']['contexte'][$page]; |
|
| 161 | - } |
|
| 162 | - if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 163 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 164 | - } |
|
| 165 | - if ($type == 'page' or $disponible[$type]) { |
|
| 166 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - $squelette = $flux['data']; |
|
| 171 | - } |
|
| 172 | - // layout specifiques par type et compositions : |
|
| 173 | - // body-article.html |
|
| 174 | - // body-sommaire.html |
|
| 175 | - // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 176 | - // meme dossier que body.html |
|
| 177 | - if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 178 | - if (isset($flux['args']['contexte']['type-page']) |
|
| 179 | - and ( |
|
| 180 | - (isset($flux['args']['contexte']['composition']) |
|
| 181 | - and file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page'] . "-" . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 182 | - or |
|
| 183 | - file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 184 | - ) |
|
| 185 | - ) { |
|
| 186 | - $flux['data'] = $f; |
|
| 187 | - } |
|
| 188 | - } elseif ($fond == 'structure' |
|
| 189 | - and z_sanitize_var_zajax() |
|
| 190 | - and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 191 | - ) { |
|
| 192 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 193 | - } // chercher le fond correspondant a la composition |
|
| 194 | - elseif (isset($flux['args']['contexte']['composition']) |
|
| 195 | - and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 196 | - and $dir = substr($fond, $prefix_length) |
|
| 197 | - and $dir = explode('/', $dir) |
|
| 198 | - and $dir = reset($dir) |
|
| 199 | - and in_array($dir, $z_blocs) |
|
| 200 | - and $f = find_in_path($prefix_path . $prepend . $fond . "-" . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 201 | - ) { |
|
| 202 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return $flux; |
|
| 32 | + static $prefix_path = null; |
|
| 33 | + static $prefix_length; |
|
| 34 | + static $z_blocs; |
|
| 35 | + static $apl_constant; |
|
| 36 | + static $page; |
|
| 37 | + static $disponible = array(); |
|
| 38 | + static $echafauder; |
|
| 39 | + static $prepend = ""; |
|
| 40 | + |
|
| 41 | + if (!isset($prefix_path)) { |
|
| 42 | + $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | + if (test_espace_prive()) { |
|
| 44 | + $prefix_path = "prive/squelettes/"; |
|
| 45 | + $prefix_length = strlen($prefix_path); |
|
| 46 | + $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | + $page = 'exec'; |
|
| 48 | + $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | + define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | + } else { |
|
| 51 | + $prefix_path = ""; |
|
| 52 | + $prefix_length = 0; |
|
| 53 | + $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | + $page = _SPIP_PAGE; |
|
| 55 | + $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(_DIR_PLUGIN_DIST, |
|
| 57 | + '/') : '')); |
|
| 58 | + } |
|
| 59 | + $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ""); |
|
| 60 | + } |
|
| 61 | + $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 62 | + |
|
| 63 | + $fond = $flux['args']['fond']; |
|
| 64 | + |
|
| 65 | + if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 66 | + $fond = substr($fond, $prefix_length); |
|
| 67 | + $squelette = $flux['data']; |
|
| 68 | + $ext = $flux['args']['ext']; |
|
| 69 | + // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 70 | + if (defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 71 | + and $dir = explode('/', $fond) |
|
| 72 | + and count($dir) == 2 // pas un sous repertoire |
|
| 73 | + and $dir = reset($dir) |
|
| 74 | + and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 75 | + and defined($apl_constant) |
|
| 76 | + and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 77 | + and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 78 | + ) { |
|
| 79 | + $flux['data'] = $pipe; |
|
| 80 | + |
|
| 81 | + return $flux; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 85 | + if ($squelette and !z_fond_valide($squelette)) { |
|
| 86 | + $squelette = ""; |
|
| 87 | + $echafauder = ""; |
|
| 88 | + } |
|
| 89 | + if ($prepend) { |
|
| 90 | + $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 91 | + if ($squelette) { |
|
| 92 | + $flux['data'] = $squelette; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // gerer les squelettes non trouves |
|
| 97 | + // -> router vers les /dist.html |
|
| 98 | + // ou scaffolding ou page automatique les contenus |
|
| 99 | + if (!$squelette) { |
|
| 100 | + |
|
| 101 | + // si on est sur un ?page=XX non trouve |
|
| 102 | + if ((isset($flux['args']['contexte'][$page]) |
|
| 103 | + and $flux['args']['contexte'][$page] == $fond) |
|
| 104 | + or (isset($flux['args']['contexte']['type-page']) |
|
| 105 | + and $flux['args']['contexte']['type-page'] == $fond) |
|
| 106 | + or ($fond == 'sommaire' |
|
| 107 | + and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 108 | + ) { |
|
| 109 | + |
|
| 110 | + // si on est sur un ?page=XX non trouve |
|
| 111 | + // se brancher sur contenu/xx si il existe |
|
| 112 | + // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 113 | + if (!isset($disponible[$fond])) { |
|
| 114 | + $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if ($disponible[$fond]) { |
|
| 118 | + $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // echafaudage : |
|
| 123 | + // si c'est un fond de contenu d'un objet en base |
|
| 124 | + // generer un fond automatique a la volee pour les webmestres |
|
| 125 | + elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 126 | + $type = substr($fond, strlen($z_contenu) + 1); |
|
| 127 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 128 | + $type = $flux['args']['contexte'][$page]; |
|
| 129 | + } |
|
| 130 | + if (!isset($disponible[$type])) { |
|
| 131 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 132 | + } |
|
| 133 | + if (is_string($disponible[$type])) { |
|
| 134 | + $flux['data'] = $disponible[$type]; |
|
| 135 | + } elseif ($echafauder |
|
| 136 | + and include_spip('inc/autoriser') |
|
| 137 | + and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 138 | + and autoriser('echafauder', $type) |
|
| 139 | + and $is = $disponible[$type] |
|
| 140 | + and is_array($is) |
|
| 141 | + ) { |
|
| 142 | + $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 143 | + } else { |
|
| 144 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, '404', $ext, |
|
| 145 | + $echafauder)); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 150 | + // et si il y a bien un contenu correspondant ou echafaudable |
|
| 151 | + // se rabbatre sur le dist.html du bloc concerne |
|
| 152 | + else { |
|
| 153 | + if ($dir = explode('/', $fond) |
|
| 154 | + and $dir = reset($dir) |
|
| 155 | + and $dir !== $z_contenu |
|
| 156 | + and in_array($dir, $z_blocs) |
|
| 157 | + ) { |
|
| 158 | + $type = substr($fond, strlen("$dir/")); |
|
| 159 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 160 | + $type = $flux['args']['contexte'][$page]; |
|
| 161 | + } |
|
| 162 | + if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 163 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 164 | + } |
|
| 165 | + if ($type == 'page' or $disponible[$type]) { |
|
| 166 | + $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + $squelette = $flux['data']; |
|
| 171 | + } |
|
| 172 | + // layout specifiques par type et compositions : |
|
| 173 | + // body-article.html |
|
| 174 | + // body-sommaire.html |
|
| 175 | + // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 176 | + // meme dossier que body.html |
|
| 177 | + if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 178 | + if (isset($flux['args']['contexte']['type-page']) |
|
| 179 | + and ( |
|
| 180 | + (isset($flux['args']['contexte']['composition']) |
|
| 181 | + and file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page'] . "-" . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 182 | + or |
|
| 183 | + file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 184 | + ) |
|
| 185 | + ) { |
|
| 186 | + $flux['data'] = $f; |
|
| 187 | + } |
|
| 188 | + } elseif ($fond == 'structure' |
|
| 189 | + and z_sanitize_var_zajax() |
|
| 190 | + and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 191 | + ) { |
|
| 192 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 193 | + } // chercher le fond correspondant a la composition |
|
| 194 | + elseif (isset($flux['args']['contexte']['composition']) |
|
| 195 | + and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 196 | + and $dir = substr($fond, $prefix_length) |
|
| 197 | + and $dir = explode('/', $dir) |
|
| 198 | + and $dir = reset($dir) |
|
| 199 | + and in_array($dir, $z_blocs) |
|
| 200 | + and $f = find_in_path($prefix_path . $prepend . $fond . "-" . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 201 | + ) { |
|
| 202 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return $flux; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | /** |
@@ -213,18 +213,18 @@ discard block |
||
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | 215 | function z_blocs($espace_prive = false) { |
| 216 | - if ($espace_prive) { |
|
| 217 | - return (isset($GLOBALS['z_blocs_ecrire']) ? $GLOBALS['z_blocs_ecrire'] : array( |
|
| 218 | - 'contenu', |
|
| 219 | - 'navigation', |
|
| 220 | - 'extra', |
|
| 221 | - 'head', |
|
| 222 | - 'hierarchie', |
|
| 223 | - 'top' |
|
| 224 | - )); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return (isset($GLOBALS['z_blocs']) ? $GLOBALS['z_blocs'] : array('contenu')); |
|
| 216 | + if ($espace_prive) { |
|
| 217 | + return (isset($GLOBALS['z_blocs_ecrire']) ? $GLOBALS['z_blocs_ecrire'] : array( |
|
| 218 | + 'contenu', |
|
| 219 | + 'navigation', |
|
| 220 | + 'extra', |
|
| 221 | + 'head', |
|
| 222 | + 'hierarchie', |
|
| 223 | + 'top' |
|
| 224 | + )); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + return (isset($GLOBALS['z_blocs']) ? $GLOBALS['z_blocs'] : array('contenu')); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -239,11 +239,11 @@ discard block |
||
| 239 | 239 | * @return mixed |
| 240 | 240 | */ |
| 241 | 241 | function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) { |
| 242 | - if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 243 | - return $d; |
|
| 244 | - } |
|
| 242 | + if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 243 | + return $d; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - return $echafauder ? z_echafaudable($type) : false; |
|
| 246 | + return $echafauder ? z_echafaudable($type) : false; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -257,13 +257,13 @@ discard block |
||
| 257 | 257 | * `true` si on peut l'utiliser, `false` sinon. |
| 258 | 258 | **/ |
| 259 | 259 | function z_fond_valide($squelette) { |
| 260 | - if (!_ZCORE_EXCLURE_PATH |
|
| 261 | - or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 262 | - ) { |
|
| 263 | - return true; |
|
| 264 | - } |
|
| 260 | + if (!_ZCORE_EXCLURE_PATH |
|
| 261 | + or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 262 | + ) { |
|
| 263 | + return true; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - return false; |
|
| 266 | + return false; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -281,14 +281,14 @@ discard block |
||
| 281 | 281 | * @return string |
| 282 | 282 | */ |
| 283 | 283 | function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) { |
| 284 | - if ( |
|
| 285 | - (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 286 | - or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 287 | - ) { |
|
| 288 | - return substr($f, 0, -strlen(".$ext")); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - return ""; |
|
| 284 | + if ( |
|
| 285 | + (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 286 | + or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 287 | + ) { |
|
| 288 | + return substr($f, 0, -strlen(".$ext")); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + return ""; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -300,51 +300,51 @@ discard block |
||
| 300 | 300 | * @return bool |
| 301 | 301 | */ |
| 302 | 302 | function z_echafaudable($type) { |
| 303 | - static $pages = null; |
|
| 304 | - static $echafaudable = array(); |
|
| 305 | - if (isset($echafaudable[$type])) { |
|
| 306 | - return $echafaudable[$type]; |
|
| 307 | - } |
|
| 308 | - if (preg_match(',[^\w],', $type)) { |
|
| 309 | - return $echafaudable[$type] = false; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - if (test_espace_prive()) { |
|
| 313 | - if (!function_exists('trouver_objet_exec')) { |
|
| 314 | - include_spip('inc/pipelines_ecrire'); |
|
| 315 | - } |
|
| 316 | - if ($e = trouver_objet_exec($type)) { |
|
| 317 | - return $echafaudable[$type] = array($e['table'], $e['table_objet_sql'], $e); |
|
| 318 | - } else { |
|
| 319 | - // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 320 | - if (($t = objet_type($type, false)) !== $type |
|
| 321 | - and $e = trouver_objet_exec($t) |
|
| 322 | - ) { |
|
| 323 | - return $echafaudable[$type] = array($e['table'], $e['table_objet_sql'], $t); |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - } else { |
|
| 327 | - if (is_null($pages)) { |
|
| 328 | - $pages = array(); |
|
| 329 | - $liste = lister_tables_objets_sql(); |
|
| 330 | - foreach ($liste as $t => $d) { |
|
| 331 | - if ($d['page']) { |
|
| 332 | - $pages[$d['page']] = array($d['table_objet'], $t); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - if (!isset($pages[$type])) { |
|
| 337 | - return $echafaudable[$type] = false; |
|
| 338 | - } |
|
| 339 | - if (count($pages[$type]) == 2) { |
|
| 340 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | - $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - return $echafaudable[$type] = $pages[$type]; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - return $echafaudable[$type] = false; |
|
| 303 | + static $pages = null; |
|
| 304 | + static $echafaudable = array(); |
|
| 305 | + if (isset($echafaudable[$type])) { |
|
| 306 | + return $echafaudable[$type]; |
|
| 307 | + } |
|
| 308 | + if (preg_match(',[^\w],', $type)) { |
|
| 309 | + return $echafaudable[$type] = false; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + if (test_espace_prive()) { |
|
| 313 | + if (!function_exists('trouver_objet_exec')) { |
|
| 314 | + include_spip('inc/pipelines_ecrire'); |
|
| 315 | + } |
|
| 316 | + if ($e = trouver_objet_exec($type)) { |
|
| 317 | + return $echafaudable[$type] = array($e['table'], $e['table_objet_sql'], $e); |
|
| 318 | + } else { |
|
| 319 | + // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 320 | + if (($t = objet_type($type, false)) !== $type |
|
| 321 | + and $e = trouver_objet_exec($t) |
|
| 322 | + ) { |
|
| 323 | + return $echafaudable[$type] = array($e['table'], $e['table_objet_sql'], $t); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + } else { |
|
| 327 | + if (is_null($pages)) { |
|
| 328 | + $pages = array(); |
|
| 329 | + $liste = lister_tables_objets_sql(); |
|
| 330 | + foreach ($liste as $t => $d) { |
|
| 331 | + if ($d['page']) { |
|
| 332 | + $pages[$d['page']] = array($d['table_objet'], $t); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + if (!isset($pages[$type])) { |
|
| 337 | + return $echafaudable[$type] = false; |
|
| 338 | + } |
|
| 339 | + if (count($pages[$type]) == 2) { |
|
| 340 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 341 | + $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + return $echafaudable[$type] = $pages[$type]; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + return $echafaudable[$type] = false; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | |
@@ -361,46 +361,46 @@ discard block |
||
| 361 | 361 | * @return string |
| 362 | 362 | */ |
| 363 | 363 | function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) { |
| 364 | - $scaffold = ""; |
|
| 365 | - |
|
| 366 | - // page objet ou objet_edit |
|
| 367 | - if (is_array($desc_exec)) { |
|
| 368 | - $type = $desc_exec['type']; |
|
| 369 | - $primary = $desc_exec['id_table_objet']; |
|
| 370 | - |
|
| 371 | - if ($desc_exec['edition'] === false) { |
|
| 372 | - $fond = "objet"; |
|
| 373 | - } else { |
|
| 374 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 375 | - $desc = $trouver_table($table_sql); |
|
| 376 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 377 | - $fond = 'objet_edit'; |
|
| 378 | - } else { |
|
| 379 | - $fond = 'objet_edit.sans_rubrique'; |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - $dir = z_blocs(test_espace_prive()); |
|
| 383 | - $dir = reset($dir); |
|
| 384 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ",objet=" . $type . ",id_objet=#" . strtoupper($primary) . ",env}>"; |
|
| 385 | - } // page objets |
|
| 386 | - elseif ($type = $desc_exec and strpos($type, "/") === false) { |
|
| 387 | - $dir = z_blocs(test_espace_prive()); |
|
| 388 | - $dir = reset($dir); |
|
| 389 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ",env} />"; |
|
| 390 | - } |
|
| 391 | - // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 392 | - // et objet et tire de $table |
|
| 393 | - elseif ($fond = $desc_exec) { |
|
| 394 | - $dir = md5(dirname($fond)); |
|
| 395 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ",env} />"; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - $base_dir = sous_repertoire(_DIR_CACHE, "scaffold", false); |
|
| 399 | - $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 400 | - $f = $base_dir . "$exec"; |
|
| 401 | - ecrire_fichier("$f.$ext", $scaffold); |
|
| 402 | - |
|
| 403 | - return $f; |
|
| 364 | + $scaffold = ""; |
|
| 365 | + |
|
| 366 | + // page objet ou objet_edit |
|
| 367 | + if (is_array($desc_exec)) { |
|
| 368 | + $type = $desc_exec['type']; |
|
| 369 | + $primary = $desc_exec['id_table_objet']; |
|
| 370 | + |
|
| 371 | + if ($desc_exec['edition'] === false) { |
|
| 372 | + $fond = "objet"; |
|
| 373 | + } else { |
|
| 374 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 375 | + $desc = $trouver_table($table_sql); |
|
| 376 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 377 | + $fond = 'objet_edit'; |
|
| 378 | + } else { |
|
| 379 | + $fond = 'objet_edit.sans_rubrique'; |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + $dir = z_blocs(test_espace_prive()); |
|
| 383 | + $dir = reset($dir); |
|
| 384 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ",objet=" . $type . ",id_objet=#" . strtoupper($primary) . ",env}>"; |
|
| 385 | + } // page objets |
|
| 386 | + elseif ($type = $desc_exec and strpos($type, "/") === false) { |
|
| 387 | + $dir = z_blocs(test_espace_prive()); |
|
| 388 | + $dir = reset($dir); |
|
| 389 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ",env} />"; |
|
| 390 | + } |
|
| 391 | + // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 392 | + // et objet et tire de $table |
|
| 393 | + elseif ($fond = $desc_exec) { |
|
| 394 | + $dir = md5(dirname($fond)); |
|
| 395 | + $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ",env} />"; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + $base_dir = sous_repertoire(_DIR_CACHE, "scaffold", false); |
|
| 399 | + $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 400 | + $f = $base_dir . "$exec"; |
|
| 401 | + ecrire_fichier("$f.$ext", $scaffold); |
|
| 402 | + |
|
| 403 | + return $f; |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
@@ -409,16 +409,16 @@ discard block |
||
| 409 | 409 | * @return bool|string |
| 410 | 410 | */ |
| 411 | 411 | function z_sanitize_var_zajax() { |
| 412 | - $z_ajax = _request('var_zajax'); |
|
| 413 | - if (!$z_ajax) { |
|
| 414 | - return false; |
|
| 415 | - } |
|
| 416 | - if (!$z_blocs = z_blocs(test_espace_prive()) |
|
| 417 | - or !in_array($z_ajax, $z_blocs) |
|
| 418 | - ) { |
|
| 419 | - set_request('var_zajax'); // enlever cette demande incongrue |
|
| 420 | - $z_ajax = false; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return $z_ajax; |
|
| 412 | + $z_ajax = _request('var_zajax'); |
|
| 413 | + if (!$z_ajax) { |
|
| 414 | + return false; |
|
| 415 | + } |
|
| 416 | + if (!$z_blocs = z_blocs(test_espace_prive()) |
|
| 417 | + or !in_array($z_ajax, $z_blocs) |
|
| 418 | + ) { |
|
| 419 | + set_request('var_zajax'); // enlever cette demande incongrue |
|
| 420 | + $z_ajax = false; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return $z_ajax; |
|
| 424 | 424 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
| 54 | 54 | $page = _SPIP_PAGE; |
| 55 | 55 | $echafauder = charger_fonction('echafauder', 'public', true); |
| 56 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(_DIR_PLUGIN_DIST, |
|
| 56 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST') ? '|\b'.rtrim(_DIR_PLUGIN_DIST, |
|
| 57 | 57 | '/') : '')); |
| 58 | 58 | } |
| 59 | 59 | $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ""); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
| 75 | 75 | and defined($apl_constant) |
| 76 | 76 | and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
| 77 | - and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 77 | + and $pipe = z_trouver_bloc($prefix_path.$prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 78 | 78 | ) { |
| 79 | 79 | $flux['data'] = $pipe; |
| 80 | 80 | |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $echafauder = ""; |
| 88 | 88 | } |
| 89 | 89 | if ($prepend) { |
| 90 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 90 | + $squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, -strlen(".$ext")); |
|
| 91 | 91 | if ($squelette) { |
| 92 | 92 | $flux['data'] = $squelette; |
| 93 | 93 | } |
@@ -111,11 +111,11 @@ discard block |
||
| 111 | 111 | // se brancher sur contenu/xx si il existe |
| 112 | 112 | // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
| 113 | 113 | if (!isset($disponible[$fond])) { |
| 114 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 114 | + $disponible[$fond] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | if ($disponible[$fond]) { |
| 118 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 118 | + $flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, -strlen(".$ext")); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $type = $flux['args']['contexte'][$page]; |
| 129 | 129 | } |
| 130 | 130 | if (!isset($disponible[$type])) { |
| 131 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 131 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 132 | 132 | } |
| 133 | 133 | if (is_string($disponible[$type])) { |
| 134 | 134 | $flux['data'] = $disponible[$type]; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | ) { |
| 142 | 142 | $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
| 143 | 143 | } else { |
| 144 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, '404', $ext, |
|
| 144 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, '404', $ext, |
|
| 145 | 145 | $echafauder)); |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | $type = $flux['args']['contexte'][$page]; |
| 161 | 161 | } |
| 162 | 162 | if ($type !== 'page' and !isset($disponible[$type])) { |
| 163 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 163 | + $disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 164 | 164 | } |
| 165 | 165 | if ($type == 'page' or $disponible[$type]) { |
| 166 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 166 | + $flux['data'] = z_trouver_bloc($prefix_path.$prepend, $dir, 'dist', $ext); |
|
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | } |
@@ -178,16 +178,16 @@ discard block |
||
| 178 | 178 | if (isset($flux['args']['contexte']['type-page']) |
| 179 | 179 | and ( |
| 180 | 180 | (isset($flux['args']['contexte']['composition']) |
| 181 | - and file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page'] . "-" . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 181 | + and file_exists(($f = $squelette."-".$flux['args']['contexte']['type-page']."-".$flux['args']['contexte']['composition']).".$ext")) |
|
| 182 | 182 | or |
| 183 | - file_exists(($f = $squelette . "-" . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 183 | + file_exists(($f = $squelette."-".$flux['args']['contexte']['type-page']).".$ext") |
|
| 184 | 184 | ) |
| 185 | 185 | ) { |
| 186 | 186 | $flux['data'] = $f; |
| 187 | 187 | } |
| 188 | 188 | } elseif ($fond == 'structure' |
| 189 | 189 | and z_sanitize_var_zajax() |
| 190 | - and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 190 | + and $f = find_in_path($prefix_path.$prepend.'ajax'.".$ext") |
|
| 191 | 191 | ) { |
| 192 | 192 | $flux['data'] = substr($f, 0, -strlen(".$ext")); |
| 193 | 193 | } // chercher le fond correspondant a la composition |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | and $dir = explode('/', $dir) |
| 198 | 198 | and $dir = reset($dir) |
| 199 | 199 | and in_array($dir, $z_blocs) |
| 200 | - and $f = find_in_path($prefix_path . $prepend . $fond . "-" . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 200 | + and $f = find_in_path($prefix_path.$prepend.$fond."-".$flux['args']['contexte']['composition'].".$ext") |
|
| 201 | 201 | ) { |
| 202 | 202 | $flux['data'] = substr($f, 0, -strlen(".$ext")); |
| 203 | 203 | } |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | **/ |
| 259 | 259 | function z_fond_valide($squelette) { |
| 260 | 260 | if (!_ZCORE_EXCLURE_PATH |
| 261 | - or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 261 | + or !preg_match(',('._ZCORE_EXCLURE_PATH.')/,', $squelette) |
|
| 262 | 262 | ) { |
| 263 | 263 | return true; |
| 264 | 264 | } |
@@ -381,23 +381,23 @@ discard block |
||
| 381 | 381 | } |
| 382 | 382 | $dir = z_blocs(test_espace_prive()); |
| 383 | 383 | $dir = reset($dir); |
| 384 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ",objet=" . $type . ",id_objet=#" . strtoupper($primary) . ",env}>"; |
|
| 384 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.",objet=".$type.",id_objet=#".strtoupper($primary).",env}>"; |
|
| 385 | 385 | } // page objets |
| 386 | 386 | elseif ($type = $desc_exec and strpos($type, "/") === false) { |
| 387 | 387 | $dir = z_blocs(test_espace_prive()); |
| 388 | 388 | $dir = reset($dir); |
| 389 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ",env} />"; |
|
| 389 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.",env} />"; |
|
| 390 | 390 | } |
| 391 | 391 | // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
| 392 | 392 | // et objet et tire de $table |
| 393 | 393 | elseif ($fond = $desc_exec) { |
| 394 | 394 | $dir = md5(dirname($fond)); |
| 395 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ",env} />"; |
|
| 395 | + $scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).",env} />"; |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | $base_dir = sous_repertoire(_DIR_CACHE, "scaffold", false); |
| 399 | 399 | $base_dir = sous_repertoire($base_dir, $dir, false); |
| 400 | - $f = $base_dir . "$exec"; |
|
| 400 | + $f = $base_dir."$exec"; |
|
| 401 | 401 | ecrire_fichier("$f.$ext", $scaffold); |
| 402 | 402 | |
| 403 | 403 | return $f; |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | /** |
| 29 | 29 | * Retourne l'URL de redirection d'un article virtuel, seulement si il est publié |
| 30 | 30 | * |
| 31 | - * @param $id_article |
|
| 32 | - * @param $connect |
|
| 33 | - * @return array|bool|null |
|
| 31 | + * @param integer $id_article |
|
| 32 | + * @param string $connect |
|
| 33 | + * @return string |
|
| 34 | 34 | */ |
| 35 | 35 | function quete_virtuel($id_article, $connect) { |
| 36 | 36 | return sql_getfetsel( |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @uses quete_parent_lang() |
| 123 | 123 | * |
| 124 | 124 | * @param int $id_article |
| 125 | - * @param $serveur |
|
| 125 | + * @param string $serveur |
|
| 126 | 126 | * @return int |
| 127 | 127 | */ |
| 128 | 128 | function quete_rubrique($id_article, $serveur) { |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * |
| 294 | 294 | * @param int $id_document |
| 295 | 295 | * @param string $serveur |
| 296 | - * @return array|bool|null |
|
| 296 | + * @return string |
|
| 297 | 297 | */ |
| 298 | 298 | function quete_fichier($id_document, $serveur = '') { |
| 299 | 299 | return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur); |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | return sql_getfetsel( |
| 37 | 37 | 'virtuel', |
| 38 | 38 | 'spip_articles', |
| 39 | - array('id_article=' . intval($id_article), "statut='publie'"), |
|
| 39 | + array('id_article='.intval($id_article), "statut='publie'"), |
|
| 40 | 40 | '', |
| 41 | 41 | '', |
| 42 | 42 | '', |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $cache_quete[$connect][$table][$id] = sql_fetsel( |
| 79 | 79 | $cache_quete[$connect][$table]['_select'], |
| 80 | 80 | $table, |
| 81 | - $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 81 | + $cache_quete[$connect][$table]['_id'].'='.intval($id), |
|
| 82 | 82 | '', |
| 83 | 83 | '', |
| 84 | 84 | '', |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | return |
| 172 | 172 | (isset($GLOBALS['meta']['date_prochain_postdate']) |
| 173 | 173 | and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
| 174 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 174 | + ? "$champ_date<".sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 175 | 175 | : '1=1'; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | and $id_table = reset($objet) |
| 230 | 230 | and $objet = objet_type($id_table) |
| 231 | 231 | ) { |
| 232 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 232 | + $w = "$mstatut<>".sql_quote($v); |
|
| 233 | 233 | |
| 234 | 234 | // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
| 235 | 235 | // sinon l’auteur en session |
@@ -243,22 +243,22 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // dans ce cas (admin en general), pas de filtrage sur ce statut |
| 246 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 246 | + if (!autoriser('previsualiser'.$v, $objet, '', $id_auteur)) { |
|
| 247 | 247 | // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
| 248 | 248 | if (!$id_auteur) { |
| 249 | 249 | $where[] = $w; |
| 250 | 250 | } else { |
| 251 | 251 | $primary = id_table_objet($objet); |
| 252 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 252 | + $where[] = "($w OR $id_table.$primary IN (".sql_get_select( |
|
| 253 | 253 | 'ssss.id_objet', |
| 254 | 254 | 'spip_auteurs_liens AS ssss', |
| 255 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 255 | + 'ssss.objet='.sql_quote($objet).' AND ssss.id_auteur='.intval($id_auteur), |
|
| 256 | 256 | '', |
| 257 | 257 | '', |
| 258 | 258 | '', |
| 259 | 259 | '', |
| 260 | 260 | $serveur |
| 261 | - ) . '))'; |
|
| 261 | + ).'))'; |
|
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | 264 | } // ignorer ce statut si on ne sait pas comment le filtrer |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | * @return array|bool|null |
| 297 | 297 | */ |
| 298 | 298 | function quete_fichier($id_document, $serveur = '') { |
| 299 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur); |
|
| 299 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document='.intval($id_document)), '', array(), '', '', $serveur); |
|
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | /** |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | * @return array|bool |
| 308 | 308 | */ |
| 309 | 309 | function quete_document($id_document, $serveur = '') { |
| 310 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur); |
|
| 310 | + return sql_fetsel('*', 'spip_documents', ('id_document='.intval($id_document)), '', array(), '', '', $serveur); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | /** |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | * @return array|bool|null |
| 319 | 319 | */ |
| 320 | 320 | function quete_meta($nom, $serveur) { |
| 321 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 321 | + return sql_getfetsel('valeur', 'spip_meta', 'nom='.sql_quote($nom), '', '', '', '', $serveur); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -372,9 +372,9 @@ discard block |
||
| 372 | 372 | // qui permet de distinguer le changement de logo |
| 373 | 373 | // et placer un expire sur le dossier IMG/ |
| 374 | 374 | $res = array( |
| 375 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 376 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 377 | - (!$taille ? '' : (' ' . $taille[3])) |
|
| 375 | + $on['chemin'].($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 376 | + ($off ? $off['chemin'].($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 377 | + (!$taille ? '' : (' '.$taille[3])) |
|
| 378 | 378 | ); |
| 379 | 379 | $res['src'] = $res[0]; |
| 380 | 380 | $res['logo_on'] = $res[0]; |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | // si c'est une vignette type doc, la renvoyer direct |
| 471 | 471 | if (strcmp($logo, _DIR_PLUGINS) == 0 |
| 472 | 472 | or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
| 473 | - or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 473 | + or strcmp($logo, _DIR_RACINE.'prive/') == 0 |
|
| 474 | 474 | ) { |
| 475 | 475 | return $logo; |
| 476 | 476 | } |
@@ -589,8 +589,7 @@ discard block |
||
| 589 | 589 | // qu'une fois (par squelette) et on conserve le resultat |
| 590 | 590 | // en static. |
| 591 | 591 | if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
| 592 | - $principal = isset($reference[$type]) ? $reference[$type] : |
|
| 593 | - // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 592 | + $principal = isset($reference[$type]) ? $reference[$type] : // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 594 | 593 | // et donne la reference dynamique @type=xx dans le contexte |
| 595 | 594 | (isset($reference["@$type"]) ? $reference["@$type"] : ''); |
| 596 | 595 | // le parent fournit en argument est le parent de $id, pas celui de $principal |
@@ -618,7 +617,7 @@ discard block |
||
| 618 | 617 | $exposer[$m][$type][$principal] = true; |
| 619 | 618 | if ($type == 'id_mot') { |
| 620 | 619 | if (!$parent) { |
| 621 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 620 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot='.intval($principal), '', '', '', '', $connect); |
|
| 622 | 621 | } |
| 623 | 622 | if ($parent) { |
| 624 | 623 | $exposer[$m]['id_groupe'][$parent] = true; |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | * @return array|bool|null |
| 34 | 34 | */ |
| 35 | 35 | function quete_virtuel($id_article, $connect) { |
| 36 | - return sql_getfetsel( |
|
| 37 | - 'virtuel', |
|
| 38 | - 'spip_articles', |
|
| 39 | - array('id_article=' . intval($id_article), "statut='publie'"), |
|
| 40 | - '', |
|
| 41 | - '', |
|
| 42 | - '', |
|
| 43 | - '', |
|
| 44 | - $connect |
|
| 45 | - ); |
|
| 36 | + return sql_getfetsel( |
|
| 37 | + 'virtuel', |
|
| 38 | + 'spip_articles', |
|
| 39 | + array('id_article=' . intval($id_article), "statut='publie'"), |
|
| 40 | + '', |
|
| 41 | + '', |
|
| 42 | + '', |
|
| 43 | + '', |
|
| 44 | + $connect |
|
| 45 | + ); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -57,38 +57,38 @@ discard block |
||
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | 59 | function quete_parent_lang($table, $id, $connect = '') { |
| 60 | - static $cache_quete = array(); |
|
| 61 | - |
|
| 62 | - if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | - if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | - if (!$desc = $trouver_table($table, |
|
| 66 | - $connect) or !isset($desc['field']['id_rubrique']) |
|
| 67 | - ) { |
|
| 68 | - // pas de parent rubrique, on passe |
|
| 69 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 70 | - } else { |
|
| 71 | - $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 72 | - $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 73 | - $cache_quete[$connect][$table]['_select'] = $select; |
|
| 74 | - $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - if ($cache_quete[$connect][$table]['_select']) { |
|
| 78 | - $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 79 | - $cache_quete[$connect][$table]['_select'], |
|
| 80 | - $table, |
|
| 81 | - $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 82 | - '', |
|
| 83 | - '', |
|
| 84 | - '', |
|
| 85 | - '', |
|
| 86 | - $connect |
|
| 87 | - ); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 60 | + static $cache_quete = array(); |
|
| 61 | + |
|
| 62 | + if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 63 | + if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 64 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 65 | + if (!$desc = $trouver_table($table, |
|
| 66 | + $connect) or !isset($desc['field']['id_rubrique']) |
|
| 67 | + ) { |
|
| 68 | + // pas de parent rubrique, on passe |
|
| 69 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 70 | + } else { |
|
| 71 | + $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 72 | + $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 73 | + $cache_quete[$connect][$table]['_select'] = $select; |
|
| 74 | + $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + if ($cache_quete[$connect][$table]['_select']) { |
|
| 78 | + $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 79 | + $cache_quete[$connect][$table]['_select'], |
|
| 80 | + $table, |
|
| 81 | + $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 82 | + '', |
|
| 83 | + '', |
|
| 84 | + '', |
|
| 85 | + '', |
|
| 86 | + $connect |
|
| 87 | + ); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return isset($cache_quete[$connect][$table][$id]) ? $cache_quete[$connect][$table][$id] : null; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | |
@@ -105,11 +105,11 @@ discard block |
||
| 105 | 105 | * @return int |
| 106 | 106 | */ |
| 107 | 107 | function quete_parent($id_rubrique, $connect = '') { |
| 108 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 109 | - return 0; |
|
| 110 | - } |
|
| 111 | - $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 112 | - return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 108 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 109 | + return 0; |
|
| 110 | + } |
|
| 111 | + $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 112 | + return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | * @return int |
| 126 | 126 | */ |
| 127 | 127 | function quete_rubrique($id_article, $serveur) { |
| 128 | - $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 128 | + $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 129 | 129 | |
| 130 | - return $id_parent['id_rubrique']; |
|
| 130 | + return $id_parent['id_rubrique']; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | * @return int |
| 142 | 142 | */ |
| 143 | 143 | function quete_profondeur($id, $connect = '') { |
| 144 | - $n = 0; |
|
| 145 | - while ($id) { |
|
| 146 | - $n++; |
|
| 147 | - $id = quete_parent($id, $connect); |
|
| 148 | - } |
|
| 144 | + $n = 0; |
|
| 145 | + while ($id) { |
|
| 146 | + $n++; |
|
| 147 | + $id = quete_parent($id, $connect); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - return $n; |
|
| 150 | + return $n; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
@@ -163,15 +163,15 @@ discard block |
||
| 163 | 163 | * Morceau de la requête SQL testant la date |
| 164 | 164 | */ |
| 165 | 165 | function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) { |
| 166 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 167 | - return '1=1'; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - return |
|
| 171 | - (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 172 | - and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 173 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 174 | - : '1=1'; |
|
| 166 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 167 | + return '1=1'; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + return |
|
| 171 | + (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 172 | + and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 173 | + ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 174 | + : '1=1'; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | |
@@ -191,100 +191,100 @@ discard block |
||
| 191 | 191 | * @return array|string |
| 192 | 192 | */ |
| 193 | 193 | function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) { |
| 194 | - static $cond = array(); |
|
| 195 | - $key = func_get_args(); |
|
| 196 | - $key = implode('-', $key); |
|
| 197 | - if (isset($cond[$key])) { |
|
| 198 | - return $cond[$key]; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - $liste_statuts = $publie; |
|
| 202 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 203 | - $liste_statuts = $previsu; |
|
| 204 | - } |
|
| 205 | - $not = false; |
|
| 206 | - if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 207 | - $not = true; |
|
| 208 | - $liste_statuts = substr($liste_statuts, 1); |
|
| 209 | - } |
|
| 210 | - // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 211 | - if (!strlen($liste_statuts)) { |
|
| 212 | - return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $liste_statuts = explode(',', $liste_statuts); |
|
| 216 | - $where = array(); |
|
| 217 | - foreach ($liste_statuts as $k => $v) { |
|
| 218 | - // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 219 | - // a ceux de l'auteur identifie |
|
| 220 | - if (strpos($v, '/') !== false) { |
|
| 221 | - $v = explode('/', $v); |
|
| 222 | - $filtre = end($v); |
|
| 223 | - $v = reset($v); |
|
| 224 | - $v = preg_replace(',\W,', '', $v); |
|
| 225 | - if ($filtre == 'auteur' |
|
| 226 | - and (strpos($mstatut, '.') !== false) |
|
| 227 | - and $objet = explode('.', $mstatut) |
|
| 228 | - and $id_table = reset($objet) |
|
| 229 | - and $objet = objet_type($id_table) |
|
| 230 | - ) { |
|
| 231 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 232 | - |
|
| 233 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 234 | - // sinon l’auteur en session |
|
| 235 | - include_spip('inc/securiser_action'); |
|
| 236 | - if ($desc = decrire_token_previsu()) { |
|
| 237 | - $id_auteur = $desc['id_auteur']; |
|
| 238 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 239 | - $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 240 | - } else { |
|
| 241 | - $id_auteur = null; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 245 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 246 | - // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 247 | - if (!$id_auteur) { |
|
| 248 | - $where[] = $w; |
|
| 249 | - } else { |
|
| 250 | - $primary = id_table_objet($objet); |
|
| 251 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 252 | - 'ssss.id_objet', |
|
| 253 | - 'spip_auteurs_liens AS ssss', |
|
| 254 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 255 | - '', |
|
| 256 | - '', |
|
| 257 | - '', |
|
| 258 | - '', |
|
| 259 | - $serveur |
|
| 260 | - ) . '))'; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 264 | - else { |
|
| 265 | - $v = ''; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - // securite |
|
| 269 | - $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 270 | - } |
|
| 271 | - $liste_statuts = array_filter($liste_statuts); |
|
| 272 | - if (count($liste_statuts) == 1) { |
|
| 273 | - $where[] = array('=', $mstatut, sql_quote(reset($liste_statuts), $serveur)); |
|
| 274 | - } else { |
|
| 275 | - $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - while (count($where) > 1) { |
|
| 279 | - $and = array('AND', array_pop($where), array_pop($where)); |
|
| 280 | - $where[] = $and; |
|
| 281 | - } |
|
| 282 | - $cond[$key] = reset($where); |
|
| 283 | - if ($not) { |
|
| 284 | - $cond[$key] = array('NOT', $cond[$key]); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - return $cond[$key]; |
|
| 194 | + static $cond = array(); |
|
| 195 | + $key = func_get_args(); |
|
| 196 | + $key = implode('-', $key); |
|
| 197 | + if (isset($cond[$key])) { |
|
| 198 | + return $cond[$key]; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + $liste_statuts = $publie; |
|
| 202 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 203 | + $liste_statuts = $previsu; |
|
| 204 | + } |
|
| 205 | + $not = false; |
|
| 206 | + if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 207 | + $not = true; |
|
| 208 | + $liste_statuts = substr($liste_statuts, 1); |
|
| 209 | + } |
|
| 210 | + // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 211 | + if (!strlen($liste_statuts)) { |
|
| 212 | + return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $liste_statuts = explode(',', $liste_statuts); |
|
| 216 | + $where = array(); |
|
| 217 | + foreach ($liste_statuts as $k => $v) { |
|
| 218 | + // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 219 | + // a ceux de l'auteur identifie |
|
| 220 | + if (strpos($v, '/') !== false) { |
|
| 221 | + $v = explode('/', $v); |
|
| 222 | + $filtre = end($v); |
|
| 223 | + $v = reset($v); |
|
| 224 | + $v = preg_replace(',\W,', '', $v); |
|
| 225 | + if ($filtre == 'auteur' |
|
| 226 | + and (strpos($mstatut, '.') !== false) |
|
| 227 | + and $objet = explode('.', $mstatut) |
|
| 228 | + and $id_table = reset($objet) |
|
| 229 | + and $objet = objet_type($id_table) |
|
| 230 | + ) { |
|
| 231 | + $w = "$mstatut<>" . sql_quote($v); |
|
| 232 | + |
|
| 233 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 234 | + // sinon l’auteur en session |
|
| 235 | + include_spip('inc/securiser_action'); |
|
| 236 | + if ($desc = decrire_token_previsu()) { |
|
| 237 | + $id_auteur = $desc['id_auteur']; |
|
| 238 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 239 | + $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 240 | + } else { |
|
| 241 | + $id_auteur = null; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 245 | + if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 246 | + // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 247 | + if (!$id_auteur) { |
|
| 248 | + $where[] = $w; |
|
| 249 | + } else { |
|
| 250 | + $primary = id_table_objet($objet); |
|
| 251 | + $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 252 | + 'ssss.id_objet', |
|
| 253 | + 'spip_auteurs_liens AS ssss', |
|
| 254 | + 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 255 | + '', |
|
| 256 | + '', |
|
| 257 | + '', |
|
| 258 | + '', |
|
| 259 | + $serveur |
|
| 260 | + ) . '))'; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 264 | + else { |
|
| 265 | + $v = ''; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + // securite |
|
| 269 | + $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 270 | + } |
|
| 271 | + $liste_statuts = array_filter($liste_statuts); |
|
| 272 | + if (count($liste_statuts) == 1) { |
|
| 273 | + $where[] = array('=', $mstatut, sql_quote(reset($liste_statuts), $serveur)); |
|
| 274 | + } else { |
|
| 275 | + $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + while (count($where) > 1) { |
|
| 279 | + $and = array('AND', array_pop($where), array_pop($where)); |
|
| 280 | + $where[] = $and; |
|
| 281 | + } |
|
| 282 | + $cond[$key] = reset($where); |
|
| 283 | + if ($not) { |
|
| 284 | + $cond[$key] = array('NOT', $cond[$key]); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + return $cond[$key]; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @return array|bool|null |
| 296 | 296 | */ |
| 297 | 297 | function quete_fichier($id_document, $serveur = '') { |
| 298 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur); |
|
| 298 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /** |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | * @return array|bool |
| 307 | 307 | */ |
| 308 | 308 | function quete_document($id_document, $serveur = '') { |
| 309 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur); |
|
| 309 | + return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', array(), '', '', $serveur); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | * @return array|bool|null |
| 318 | 318 | */ |
| 319 | 319 | function quete_meta($nom, $serveur) { |
| 320 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 320 | + return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -343,66 +343,66 @@ discard block |
||
| 343 | 343 | * Retourne soit un tableau, soit le chemin du fichier. |
| 344 | 344 | */ |
| 345 | 345 | function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag) { |
| 346 | - include_spip('base/objets'); |
|
| 347 | - $nom = strtolower($onoff); |
|
| 348 | - |
|
| 349 | - $cle_objet = id_table_objet($cle_objet); |
|
| 350 | - |
|
| 351 | - while (1) { |
|
| 352 | - $objet = objet_type($cle_objet); |
|
| 353 | - |
|
| 354 | - $on = quete_logo_objet($id, $objet, $nom); |
|
| 355 | - |
|
| 356 | - if ($on) { |
|
| 357 | - if ($flag) { |
|
| 358 | - return basename($on['chemin']); |
|
| 359 | - } else { |
|
| 360 | - $taille = @spip_getimagesize($on['chemin']); |
|
| 361 | - |
|
| 362 | - // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 363 | - // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 364 | - // alors on ne cherche pas du tout le survol ici |
|
| 365 | - if ($onoff != 'ON') { |
|
| 366 | - $off = ''; |
|
| 367 | - } else { |
|
| 368 | - // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 369 | - $off = quete_logo_objet($id, $objet, 'off'); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // on retourne une url du type IMG/artonXX?timestamp |
|
| 373 | - // qui permet de distinguer le changement de logo |
|
| 374 | - // et placer un expire sur le dossier IMG/ |
|
| 375 | - $res = array( |
|
| 376 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 377 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 378 | - (!$taille ? '' : (' ' . $taille[3])) |
|
| 379 | - ); |
|
| 380 | - $res['src'] = $res[0]; |
|
| 381 | - $res['logo_on'] = $res[0]; |
|
| 382 | - $res['logo_off'] = $res[1]; |
|
| 383 | - $res['width'] = ($taille ? $taille[0] : ''); |
|
| 384 | - $res['height'] = ($taille ? $taille[1] : ''); |
|
| 385 | - |
|
| 386 | - return $res; |
|
| 387 | - } |
|
| 388 | - } else { |
|
| 389 | - if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 390 | - return ''; |
|
| 391 | - } else { |
|
| 392 | - if ($id_rubrique) { |
|
| 393 | - $cle_objet = 'id_rubrique'; |
|
| 394 | - $id = $id_rubrique; |
|
| 395 | - $id_rubrique = 0; |
|
| 396 | - } else { |
|
| 397 | - if ($id and $cle_objet == 'id_rubrique') { |
|
| 398 | - $id = quete_parent($id); |
|
| 399 | - } else { |
|
| 400 | - return ''; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - } |
|
| 346 | + include_spip('base/objets'); |
|
| 347 | + $nom = strtolower($onoff); |
|
| 348 | + |
|
| 349 | + $cle_objet = id_table_objet($cle_objet); |
|
| 350 | + |
|
| 351 | + while (1) { |
|
| 352 | + $objet = objet_type($cle_objet); |
|
| 353 | + |
|
| 354 | + $on = quete_logo_objet($id, $objet, $nom); |
|
| 355 | + |
|
| 356 | + if ($on) { |
|
| 357 | + if ($flag) { |
|
| 358 | + return basename($on['chemin']); |
|
| 359 | + } else { |
|
| 360 | + $taille = @spip_getimagesize($on['chemin']); |
|
| 361 | + |
|
| 362 | + // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 363 | + // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 364 | + // alors on ne cherche pas du tout le survol ici |
|
| 365 | + if ($onoff != 'ON') { |
|
| 366 | + $off = ''; |
|
| 367 | + } else { |
|
| 368 | + // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 369 | + $off = quete_logo_objet($id, $objet, 'off'); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // on retourne une url du type IMG/artonXX?timestamp |
|
| 373 | + // qui permet de distinguer le changement de logo |
|
| 374 | + // et placer un expire sur le dossier IMG/ |
|
| 375 | + $res = array( |
|
| 376 | + $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 377 | + ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 378 | + (!$taille ? '' : (' ' . $taille[3])) |
|
| 379 | + ); |
|
| 380 | + $res['src'] = $res[0]; |
|
| 381 | + $res['logo_on'] = $res[0]; |
|
| 382 | + $res['logo_off'] = $res[1]; |
|
| 383 | + $res['width'] = ($taille ? $taille[0] : ''); |
|
| 384 | + $res['height'] = ($taille ? $taille[1] : ''); |
|
| 385 | + |
|
| 386 | + return $res; |
|
| 387 | + } |
|
| 388 | + } else { |
|
| 389 | + if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 390 | + return ''; |
|
| 391 | + } else { |
|
| 392 | + if ($id_rubrique) { |
|
| 393 | + $cle_objet = 'id_rubrique'; |
|
| 394 | + $id = $id_rubrique; |
|
| 395 | + $id_rubrique = 0; |
|
| 396 | + } else { |
|
| 397 | + if ($id and $cle_objet == 'id_rubrique') { |
|
| 398 | + $id = quete_parent($id); |
|
| 399 | + } else { |
|
| 400 | + return ''; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
@@ -416,37 +416,37 @@ discard block |
||
| 416 | 416 | * "on" ou "off" suivant le logo normal ou survol |
| 417 | 417 | **/ |
| 418 | 418 | function quete_logo_objet($id_objet, $objet, $mode) { |
| 419 | - static $chercher_logo; |
|
| 420 | - if (is_null($chercher_logo)) { |
|
| 421 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 422 | - } |
|
| 423 | - $cle_objet = id_table_objet($objet); |
|
| 424 | - |
|
| 425 | - // On cherche pas la méthode classique |
|
| 426 | - $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 427 | - // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 428 | - if (!empty($infos_logo)) { |
|
| 429 | - $infos_logo = array( |
|
| 430 | - 'chemin' => $infos_logo[0], |
|
| 431 | - 'timestamp' => $infos_logo[4], |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // On passe cette recherche de logo dans un pipeline |
|
| 436 | - $infos_logo = pipeline( |
|
| 437 | - 'quete_logo_objet', |
|
| 438 | - array( |
|
| 439 | - 'args' => array( |
|
| 440 | - 'id_objet' => $id_objet, |
|
| 441 | - 'objet' => $objet, |
|
| 442 | - 'cle_objet' => $cle_objet, |
|
| 443 | - 'mode' => $mode, |
|
| 444 | - ), |
|
| 445 | - 'data' => $infos_logo, |
|
| 446 | - ) |
|
| 447 | - ); |
|
| 448 | - |
|
| 449 | - return $infos_logo; |
|
| 419 | + static $chercher_logo; |
|
| 420 | + if (is_null($chercher_logo)) { |
|
| 421 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 422 | + } |
|
| 423 | + $cle_objet = id_table_objet($objet); |
|
| 424 | + |
|
| 425 | + // On cherche pas la méthode classique |
|
| 426 | + $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 427 | + // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 428 | + if (!empty($infos_logo)) { |
|
| 429 | + $infos_logo = array( |
|
| 430 | + 'chemin' => $infos_logo[0], |
|
| 431 | + 'timestamp' => $infos_logo[4], |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // On passe cette recherche de logo dans un pipeline |
|
| 436 | + $infos_logo = pipeline( |
|
| 437 | + 'quete_logo_objet', |
|
| 438 | + array( |
|
| 439 | + 'args' => array( |
|
| 440 | + 'id_objet' => $id_objet, |
|
| 441 | + 'objet' => $objet, |
|
| 442 | + 'cle_objet' => $cle_objet, |
|
| 443 | + 'mode' => $mode, |
|
| 444 | + ), |
|
| 445 | + 'data' => $infos_logo, |
|
| 446 | + ) |
|
| 447 | + ); |
|
| 448 | + |
|
| 449 | + return $infos_logo; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -459,24 +459,24 @@ discard block |
||
| 459 | 459 | * @return bool|string |
| 460 | 460 | */ |
| 461 | 461 | function quete_logo_file($row, $connect = null) { |
| 462 | - include_spip('inc/documents'); |
|
| 463 | - $logo = vignette_logo_document($row, $connect); |
|
| 464 | - if (!$logo) { |
|
| 465 | - $logo = image_du_document($row, $connect); |
|
| 466 | - } |
|
| 467 | - if (!$logo) { |
|
| 468 | - $f = charger_fonction('vignette', 'inc'); |
|
| 469 | - $logo = $f($row['extension'], false); |
|
| 470 | - } |
|
| 471 | - // si c'est une vignette type doc, la renvoyer direct |
|
| 472 | - if (strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 473 | - or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 474 | - or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 475 | - ) { |
|
| 476 | - return $logo; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - return get_spip_doc($logo); |
|
| 462 | + include_spip('inc/documents'); |
|
| 463 | + $logo = vignette_logo_document($row, $connect); |
|
| 464 | + if (!$logo) { |
|
| 465 | + $logo = image_du_document($row, $connect); |
|
| 466 | + } |
|
| 467 | + if (!$logo) { |
|
| 468 | + $f = charger_fonction('vignette', 'inc'); |
|
| 469 | + $logo = $f($row['extension'], false); |
|
| 470 | + } |
|
| 471 | + // si c'est une vignette type doc, la renvoyer direct |
|
| 472 | + if (strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 473 | + or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 474 | + or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 475 | + ) { |
|
| 476 | + return $logo; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + return get_spip_doc($logo); |
|
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | /** |
@@ -504,20 +504,20 @@ discard block |
||
| 504 | 504 | */ |
| 505 | 505 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, $connect = null) { |
| 506 | 506 | |
| 507 | - include_spip('inc/documents'); |
|
| 508 | - $logo = ''; |
|
| 509 | - if (!in_array($mode_logo, array('icone', 'apercu'))) { |
|
| 510 | - $logo = vignette_logo_document($row, $connect); |
|
| 511 | - } |
|
| 512 | - // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 513 | - if ($mode_logo == 'vignette' and !$logo) { |
|
| 514 | - return ''; |
|
| 515 | - } |
|
| 516 | - if ($mode_logo == 'icone') { |
|
| 517 | - $row['fichier'] = ''; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 507 | + include_spip('inc/documents'); |
|
| 508 | + $logo = ''; |
|
| 509 | + if (!in_array($mode_logo, array('icone', 'apercu'))) { |
|
| 510 | + $logo = vignette_logo_document($row, $connect); |
|
| 511 | + } |
|
| 512 | + // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 513 | + if ($mode_logo == 'vignette' and !$logo) { |
|
| 514 | + return ''; |
|
| 515 | + } |
|
| 516 | + if ($mode_logo == 'icone') { |
|
| 517 | + $row['fichier'] = ''; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
@@ -529,19 +529,19 @@ discard block |
||
| 529 | 529 | */ |
| 530 | 530 | function quete_html_logo($logo, $align, $lien) { |
| 531 | 531 | |
| 532 | - if (!is_array($logo)) { |
|
| 533 | - return ''; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - $contexte = []; |
|
| 537 | - foreach ($logo as $k=>$v) { |
|
| 538 | - if (!is_numeric($k)) { |
|
| 539 | - $contexte[$k] = $v; |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - $contexte['align'] = $align; |
|
| 543 | - $contexte['lien'] = $lien; |
|
| 544 | - return recuperer_fond('modeles/logo', $contexte); |
|
| 532 | + if (!is_array($logo)) { |
|
| 533 | + return ''; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + $contexte = []; |
|
| 537 | + foreach ($logo as $k=>$v) { |
|
| 538 | + if (!is_numeric($k)) { |
|
| 539 | + $contexte[$k] = $v; |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + $contexte['align'] = $align; |
|
| 543 | + $contexte['lien'] = $lien; |
|
| 544 | + return recuperer_fond('modeles/logo', $contexte); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
@@ -555,14 +555,14 @@ discard block |
||
| 555 | 555 | * @return string|false |
| 556 | 556 | */ |
| 557 | 557 | function document_spip_externe($fichier, $connect) { |
| 558 | - if ($connect) { |
|
| 559 | - $site = quete_meta('adresse_site', $connect); |
|
| 560 | - if ($site) { |
|
| 561 | - $dir = quete_meta('dir_img', $connect); |
|
| 562 | - return "$site/$dir$fichier"; |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - return false; |
|
| 558 | + if ($connect) { |
|
| 559 | + $site = quete_meta('adresse_site', $connect); |
|
| 560 | + if ($site) { |
|
| 561 | + $dir = quete_meta('dir_img', $connect); |
|
| 562 | + return "$site/$dir$fichier"; |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + return false; |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | /** |
@@ -575,23 +575,23 @@ discard block |
||
| 575 | 575 | * @return string |
| 576 | 576 | */ |
| 577 | 577 | function vignette_logo_document($row, $connect = '') { |
| 578 | - if (!$row['id_vignette']) { |
|
| 579 | - return ''; |
|
| 580 | - } |
|
| 581 | - $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 582 | - if ($url = document_spip_externe($fichier, $connect)) { |
|
| 583 | - return $url; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - $f = get_spip_doc($fichier); |
|
| 587 | - if ($f and @file_exists($f)) { |
|
| 588 | - return $f; |
|
| 589 | - } |
|
| 590 | - if ($row['mode'] !== 'vignette') { |
|
| 591 | - return ''; |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - return generer_url_entite($row['id_document'], 'document', '', '', $connect); |
|
| 578 | + if (!$row['id_vignette']) { |
|
| 579 | + return ''; |
|
| 580 | + } |
|
| 581 | + $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 582 | + if ($url = document_spip_externe($fichier, $connect)) { |
|
| 583 | + return $url; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + $f = get_spip_doc($fichier); |
|
| 587 | + if ($f and @file_exists($f)) { |
|
| 588 | + return $f; |
|
| 589 | + } |
|
| 590 | + if ($row['mode'] !== 'vignette') { |
|
| 591 | + return ''; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + return generer_url_entite($row['id_document'], 'document', '', '', $connect); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -607,68 +607,68 @@ discard block |
||
| 607 | 607 | * @return bool|string |
| 608 | 608 | */ |
| 609 | 609 | function calcul_exposer($id, $prim, $reference, $parent, $type, $connect = '') { |
| 610 | - static $exposer = array(); |
|
| 611 | - |
|
| 612 | - // Que faut-il exposer ? Tous les elements de $reference |
|
| 613 | - // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 614 | - // qu'une fois (par squelette) et on conserve le resultat |
|
| 615 | - // en static. |
|
| 616 | - if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 617 | - $principal = isset($reference[$type]) ? $reference[$type] : |
|
| 618 | - // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 619 | - // et donne la reference dynamique @type=xx dans le contexte |
|
| 620 | - (isset($reference["@$type"]) ? $reference["@$type"] : ''); |
|
| 621 | - // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 622 | - // il n'est donc pas utile |
|
| 623 | - $parent = 0; |
|
| 624 | - if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 625 | - $enfants = array('id_rubrique' => array('id_article'), 'id_groupe' => array('id_mot')); |
|
| 626 | - if (isset($enfants[$type])) { |
|
| 627 | - foreach ($enfants[$type] as $t) { |
|
| 628 | - if (isset($reference[$t]) |
|
| 629 | - // cas de la reference donnee dynamiquement par la pagination |
|
| 630 | - or isset($reference["@$t"]) |
|
| 631 | - ) { |
|
| 632 | - $type = $t; |
|
| 633 | - $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"]; |
|
| 634 | - continue; |
|
| 635 | - } |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - $exposer[$m][$type] = array(); |
|
| 640 | - if ($principal) { |
|
| 641 | - $principaux = is_array($principal) ? $principal : array($principal); |
|
| 642 | - foreach ($principaux as $principal) { |
|
| 643 | - $exposer[$m][$type][$principal] = true; |
|
| 644 | - if ($type == 'id_mot') { |
|
| 645 | - if (!$parent) { |
|
| 646 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 647 | - } |
|
| 648 | - if ($parent) { |
|
| 649 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 650 | - } |
|
| 651 | - } else { |
|
| 652 | - if ($type != 'id_groupe') { |
|
| 653 | - if (!$parent) { |
|
| 654 | - if ($type == 'id_rubrique') { |
|
| 655 | - $parent = $principal; |
|
| 656 | - } |
|
| 657 | - if ($type == 'id_article') { |
|
| 658 | - $parent = quete_rubrique($principal, $connect); |
|
| 659 | - } |
|
| 660 | - } |
|
| 661 | - do { |
|
| 662 | - $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 663 | - } while ($parent = quete_parent($parent, $connect)); |
|
| 664 | - } |
|
| 665 | - } |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - // And the winner is... |
|
| 671 | - return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 610 | + static $exposer = array(); |
|
| 611 | + |
|
| 612 | + // Que faut-il exposer ? Tous les elements de $reference |
|
| 613 | + // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 614 | + // qu'une fois (par squelette) et on conserve le resultat |
|
| 615 | + // en static. |
|
| 616 | + if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 617 | + $principal = isset($reference[$type]) ? $reference[$type] : |
|
| 618 | + // cas de la pagination indecte @xx qui positionne la page avec l'id xx |
|
| 619 | + // et donne la reference dynamique @type=xx dans le contexte |
|
| 620 | + (isset($reference["@$type"]) ? $reference["@$type"] : ''); |
|
| 621 | + // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 622 | + // il n'est donc pas utile |
|
| 623 | + $parent = 0; |
|
| 624 | + if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 625 | + $enfants = array('id_rubrique' => array('id_article'), 'id_groupe' => array('id_mot')); |
|
| 626 | + if (isset($enfants[$type])) { |
|
| 627 | + foreach ($enfants[$type] as $t) { |
|
| 628 | + if (isset($reference[$t]) |
|
| 629 | + // cas de la reference donnee dynamiquement par la pagination |
|
| 630 | + or isset($reference["@$t"]) |
|
| 631 | + ) { |
|
| 632 | + $type = $t; |
|
| 633 | + $principal = isset($reference[$type]) ? $reference[$type] : $reference["@$type"]; |
|
| 634 | + continue; |
|
| 635 | + } |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + $exposer[$m][$type] = array(); |
|
| 640 | + if ($principal) { |
|
| 641 | + $principaux = is_array($principal) ? $principal : array($principal); |
|
| 642 | + foreach ($principaux as $principal) { |
|
| 643 | + $exposer[$m][$type][$principal] = true; |
|
| 644 | + if ($type == 'id_mot') { |
|
| 645 | + if (!$parent) { |
|
| 646 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 647 | + } |
|
| 648 | + if ($parent) { |
|
| 649 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 650 | + } |
|
| 651 | + } else { |
|
| 652 | + if ($type != 'id_groupe') { |
|
| 653 | + if (!$parent) { |
|
| 654 | + if ($type == 'id_rubrique') { |
|
| 655 | + $parent = $principal; |
|
| 656 | + } |
|
| 657 | + if ($type == 'id_article') { |
|
| 658 | + $parent = quete_rubrique($principal, $connect); |
|
| 659 | + } |
|
| 660 | + } |
|
| 661 | + do { |
|
| 662 | + $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 663 | + } while ($parent = quete_parent($parent, $connect)); |
|
| 664 | + } |
|
| 665 | + } |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + // And the winner is... |
|
| 671 | + return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | /** |
@@ -683,21 +683,21 @@ discard block |
||
| 683 | 683 | * @return int |
| 684 | 684 | */ |
| 685 | 685 | function quete_debut_pagination($primary, $valeur, $pas, $iter) { |
| 686 | - // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 687 | - // ou composee, mais verifions |
|
| 688 | - if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 689 | - return 0; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - $pos = 0; |
|
| 693 | - while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 694 | - $pos++; |
|
| 695 | - } |
|
| 696 | - // si on a pas trouve |
|
| 697 | - if (!$row or $row[$primary] != $valeur) { |
|
| 698 | - return 0; |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - // sinon, calculer le bon numero de page |
|
| 702 | - return floor($pos / $pas) * $pas; |
|
| 686 | + // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 687 | + // ou composee, mais verifions |
|
| 688 | + if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 689 | + return 0; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + $pos = 0; |
|
| 693 | + while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 694 | + $pos++; |
|
| 695 | + } |
|
| 696 | + // si on a pas trouve |
|
| 697 | + if (!$row or $row[$primary] != $valeur) { |
|
| 698 | + return 0; |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + // sinon, calculer le bon numero de page |
|
| 702 | + return floor($pos / $pas) * $pas; |
|
| 703 | 703 | } |