@@ -379,8 +379,7 @@ |
||
| 379 | 379 | function executer_balise_dynamique_dans_un_modele(...$args) { |
| 380 | 380 | if (test_espace_prive()) { |
| 381 | 381 | return executer_balise_dynamique(...$args); |
| 382 | - } |
|
| 383 | - else { |
|
| 382 | + } else { |
|
| 384 | 383 | $str_args = base64_encode(serialize($args)); |
| 385 | 384 | return '<?' . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?" . ">\n"; |
| 386 | 385 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $GLOBALS['debug_objets']['courant'] = $nom; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true).$nom.'.php'; |
|
| 59 | 59 | |
| 60 | 60 | // si squelette est deja compile et perenne, le charger |
| 61 | 61 | if (!squelette_obsolete($phpfile, $source)) { |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | #} |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | + if (file_exists($lib = $squelette.'_fonctions'.'.php')) { |
|
| 72 | 72 | include_once $lib; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | eval("return true; $f ;"); |
| 97 | 97 | } catch (\ParseError $e) { |
| 98 | 98 | // Code syntaxiquement faux (critere etc mal programme') |
| 99 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | + $msg = _T('zbug_erreur_compilation').' | Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 100 | 100 | erreur_squelette($msg, $boucle); |
| 101 | 101 | // continuer pour trouver d'autres fautes eventuelles |
| 102 | 102 | // mais prevenir que c'est mort |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | if (defined('_VAR_MODE') && _VAR_MODE == 'debug') { |
| 126 | 126 | // Tracer ce qui vient d'etre compile |
| 127 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | + $GLOBALS['debug_objets']['code'][$nom.'tout'] = $code; |
|
| 128 | 128 | |
| 129 | 129 | // si c'est ce que demande le debusqueur, lui passer la main |
| 130 | 130 | if ( |
@@ -148,13 +148,13 @@ discard block |
||
| 148 | 148 | $code = " |
| 149 | 149 | /* |
| 150 | 150 | * Squelette : $sourcefile |
| 151 | - * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
|
| 152 | - * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
|
| 153 | - * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
|
| 151 | + * Date : ".gmdate('D, d M Y H:i:s', @filemtime($sourcefile)).' GMT |
|
| 152 | + * Compile : ' . gmdate('D, d M Y H:i:s', time()).' GMT |
|
| 153 | + * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : '.$noms)).' |
|
| 154 | 154 | */ '; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 157 | + $code = '<'."?php\n".$code.join('', $boucles)."\n"; |
|
| 158 | 158 | if (!defined('_VAR_NOCACHE') || !_VAR_NOCACHE) { |
| 159 | 159 | ecrire_fichier($phpfile, $code); |
| 160 | 160 | } |
@@ -215,16 +215,16 @@ discard block |
||
| 215 | 215 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 216 | 216 | |
| 217 | 217 | if ($j == 'X-Spip-Filtre' && isset($headers[$j])) { |
| 218 | - $headers[$j] .= '|' . $r[3]; |
|
| 218 | + $headers[$j] .= '|'.$r[3]; |
|
| 219 | 219 | } else { |
| 220 | - $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 220 | + $headers[$j] = str_replace(['\\\\', "\\'", '\\"'], ['\\', "'", '"'], $r[3]); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | // S'agit-il d'un resultat constant ou contenant du code php |
| 225 | 225 | $process_ins = ( |
| 226 | - !str_contains($corps, '<' . '?') |
|
| 227 | - || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 226 | + !str_contains($corps, '<'.'?') |
|
| 227 | + || str_contains($corps, '<'.'?xml') && !str_contains(str_replace('<'.'?xml', '', $corps), '<'.'?') |
|
| 228 | 228 | ) |
| 229 | 229 | ? 'html' |
| 230 | 230 | : 'php'; |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | if ($process_ins == 'html') { |
| 255 | 255 | $skel['process_ins'] = ( |
| 256 | - !str_contains($corps, '<' . '?') |
|
| 257 | - || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 256 | + !str_contains($corps, '<'.'?') |
|
| 257 | + || str_contains($corps, '<'.'?xml') && !str_contains(str_replace('<'.'?xml', '', $corps), '<'.'?') |
|
| 258 | 258 | ) |
| 259 | 259 | ? 'html' |
| 260 | 260 | : 'php'; |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | // |
| 273 | 273 | |
| 274 | 274 | /** Code PHP pour inclure une balise dynamique à l'exécution d'une page */ |
| 275 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 275 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 276 | 276 | include_once("%s"); |
| 277 | 277 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 278 | 278 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | // pas de lien symbolique sous Windows |
| 304 | 304 | && !(stristr(PHP_OS, 'WIN') && str_contains($file, ':')) |
| 305 | 305 | ) { |
| 306 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 306 | + $file = './" . _DIR_RACINE . "'.$file; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | $lang = $context_compil[4]; |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | |
| 314 | 314 | $args = array_map('argumenter_squelette', $args); |
| 315 | 315 | if (!empty($context_compil['appel_php_depuis_modele'])) { |
| 316 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 316 | + $args[0] = 'arguments_balise_dyn_depuis_modele('.$args[0].')'; |
|
| 317 | 317 | } |
| 318 | 318 | $args = join(', ', $args); |
| 319 | 319 | |
@@ -347,14 +347,14 @@ discard block |
||
| 347 | 347 | if (is_object($v)) { |
| 348 | 348 | return var_export($v, true); |
| 349 | 349 | } elseif (!is_array($v)) { |
| 350 | - return "'" . texte_script((string) $v) . "'"; |
|
| 350 | + return "'".texte_script((string) $v)."'"; |
|
| 351 | 351 | } else { |
| 352 | 352 | $out = []; |
| 353 | 353 | foreach ($v as $k => $val) { |
| 354 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 354 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - return 'array(' . join(', ', $out) . ')'; |
|
| 357 | + return 'array('.join(', ', $out).')'; |
|
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | } |
| 380 | 380 | else { |
| 381 | 381 | $str_args = base64_encode(serialize($args)); |
| 382 | - return '<?' . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?" . ">\n"; |
|
| 382 | + return '<?'."php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | // Y a-t-il une fonction de traitement des arguments ? |
| 460 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 460 | + $f = 'balise_'.$nom_balise.'_stat'; |
|
| 461 | 461 | |
| 462 | 462 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 463 | 463 | |
@@ -467,18 +467,18 @@ discard block |
||
| 467 | 467 | |
| 468 | 468 | // verifier que la fonction dyn est la, |
| 469 | 469 | // sinon se replier sur la generique si elle existe |
| 470 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 470 | + if (!function_exists('balise_'.$nom_balise.'_dyn')) { |
|
| 471 | 471 | if ( |
| 472 | 472 | ($balise_generique = chercher_balise_generique($nom)) |
| 473 | 473 | && ($nom_balise_generique = $balise_generique['nom_generique']) |
| 474 | - && ($file = include_spip('balise/' . strtolower($nom_balise_generique))) |
|
| 475 | - && function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 474 | + && ($file = include_spip('balise/'.strtolower($nom_balise_generique))) |
|
| 475 | + && function_exists('balise_'.$nom_balise_generique.'_dyn') |
|
| 476 | 476 | ) { |
| 477 | 477 | // et lui injecter en premier arg le nom de la balise |
| 478 | 478 | array_unshift($r, $nom); |
| 479 | 479 | $nom_balise = $nom_balise_generique; |
| 480 | 480 | if (!_DIR_RESTREINT) { |
| 481 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 481 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 482 | 482 | } |
| 483 | 483 | } else { |
| 484 | 484 | $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | $n = ''; |
| 581 | 581 | foreach (explode(',', $liste) as $val) { |
| 582 | 582 | if (($a = intval($val)) && $val === strval($a)) { |
| 583 | - $n .= ',' . $val; |
|
| 583 | + $n .= ','.$val; |
|
| 584 | 584 | } |
| 585 | 585 | } |
| 586 | 586 | if (strlen($n)) { |
@@ -759,8 +759,8 @@ discard block |
||
| 759 | 759 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 760 | 760 | $i = 0; |
| 761 | 761 | do { |
| 762 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 763 | - [$sous[1] . ' AS id'], |
|
| 762 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 763 | + [$sous[1].' AS id'], |
|
| 764 | 764 | $from, |
| 765 | 765 | $from_type, |
| 766 | 766 | $wheresub, |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | $id, |
| 774 | 774 | $serveur, |
| 775 | 775 | false |
| 776 | - ) . ')'); |
|
| 776 | + ).')'); |
|
| 777 | 777 | if (!$i) { |
| 778 | 778 | $i = 1; |
| 779 | 779 | $wherestring = calculer_where_to_string($where[$k]); |
@@ -792,7 +792,7 @@ discard block |
||
| 792 | 792 | if ($sous[0] == 'SUBSELECT') { |
| 793 | 793 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 794 | 794 | array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
| 795 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 795 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 796 | 796 | $sous[1], # select |
| 797 | 797 | $sous[2], #from |
| 798 | 798 | [], #from_type |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | $id, |
| 808 | 808 | $serveur, |
| 809 | 809 | false |
| 810 | - ) . ')'); |
|
| 810 | + ).')'); |
|
| 811 | 811 | } |
| 812 | 812 | array_pop($where_simples); |
| 813 | 813 | } |
@@ -870,15 +870,15 @@ discard block |
||
| 870 | 870 | // sans recours a preg_match |
| 871 | 871 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 872 | 872 | $afrom[$t][$cle] = [ |
| 873 | - "\n" . |
|
| 874 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 873 | + "\n". |
|
| 874 | + ($from_type[$cle] ?? 'INNER').' JOIN', |
|
| 875 | 875 | $from[$cle], |
| 876 | 876 | "AS $cle", |
| 877 | 877 | 'ON (', |
| 878 | 878 | "$cle.$c", |
| 879 | 879 | '=', |
| 880 | 880 | "$t.$carr", |
| 881 | - ($and ? 'AND ' . $and : '') . |
|
| 881 | + ($and ? 'AND '.$and : ''). |
|
| 882 | 882 | ')' |
| 883 | 883 | ]; |
| 884 | 884 | if (isset($afrom[$cle])) { |
@@ -916,7 +916,7 @@ discard block |
||
| 916 | 916 | $t = key($from); |
| 917 | 917 | $c = current($from); |
| 918 | 918 | reset($from); |
| 919 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 919 | + $e = '/\b('."$t\\.".join('|'.$t.'\.', $equiv).')\b/'; |
|
| 920 | 920 | if ( |
| 921 | 921 | !( |
| 922 | 922 | strpos($t, ' ') |
@@ -936,7 +936,7 @@ discard block |
||
| 936 | 936 | unset($afrom[$t][$nt]); |
| 937 | 937 | $afrom[$nt] = $afrom[$t]; |
| 938 | 938 | unset($afrom[$t]); |
| 939 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 939 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 940 | 940 | $t = $nfrom[4]; |
| 941 | 941 | $alias = ''; |
| 942 | 942 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
@@ -947,14 +947,14 @@ discard block |
||
| 947 | 947 | if ($newcle != $oldcle) { |
| 948 | 948 | // si l'ancienne cle etait deja dans le select avec un AS |
| 949 | 949 | // reprendre simplement ce AS |
| 950 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 950 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 951 | 951 | if (preg_match($as, implode(',', $select), $m)) { |
| 952 | 952 | $alias = ''; |
| 953 | 953 | } else { |
| 954 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 954 | + $alias = ', '.$nfrom[4]." AS $oldcle"; |
|
| 955 | 955 | } |
| 956 | 956 | } |
| 957 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 957 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 958 | 958 | $join = remplacer_jointnul($t, $join, $e); |
| 959 | 959 | $where = remplacer_jointnul($t, $where, $e); |
| 960 | 960 | $having = remplacer_jointnul($t, $having, $e); |
@@ -1004,9 +1004,9 @@ discard block |
||
| 1004 | 1004 | } else { |
| 1005 | 1005 | $exp = ''; |
| 1006 | 1006 | if (strtoupper($join) === 'AND') { |
| 1007 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1007 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1008 | 1008 | } else { |
| 1009 | - return $exp . join($join, $v); |
|
| 1009 | + return $exp.join($join, $v); |
|
| 1010 | 1010 | } |
| 1011 | 1011 | } |
| 1012 | 1012 | } |
@@ -1068,6 +1068,6 @@ discard block |
||
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | 1070 | return $mime_type |
| 1071 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1072 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1071 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)).'_' |
|
| 1072 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 1073 | 1073 | } |
@@ -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 | include_spip('inc/texte'); |
@@ -42,229 +42,229 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | function public_composer_dist($squelette, $mime_type, $gram, $source, string $connect = '') { |
| 44 | 44 | |
| 45 | - $skel = null; |
|
| 46 | - $boucle = null; |
|
| 47 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 48 | - |
|
| 49 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 50 | - if (function_exists($nom)) { |
|
| 51 | - return $nom; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (defined('_VAR_MODE') && _VAR_MODE == 'debug') { |
|
| 55 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 59 | - |
|
| 60 | - // si squelette est deja compile et perenne, le charger |
|
| 61 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 62 | - include_once $phpfile; |
|
| 63 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 64 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 65 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 66 | - ## eval('?'.'>'.$skel_code); |
|
| 67 | - # spip_logger('comp')->info($skel_code); |
|
| 68 | - #} |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 72 | - include_once $lib; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 76 | - |
|
| 77 | - if (function_exists($nom)) { |
|
| 78 | - return $nom; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // charger le source, si possible, et compiler |
|
| 82 | - $skel_code = ''; |
|
| 83 | - if (lire_fichier($source, $skel)) { |
|
| 84 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 85 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 89 | - if (!$skel_code) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - foreach ($skel_code as $id => $boucle) { |
|
| 94 | - $f = $boucle->return; |
|
| 95 | - try { |
|
| 96 | - eval("return true; $f ;"); |
|
| 97 | - } catch (\ParseError $e) { |
|
| 98 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 99 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 100 | - erreur_squelette($msg, $boucle); |
|
| 101 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 102 | - // mais prevenir que c'est mort |
|
| 103 | - $nom = ''; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // contexte de compil inutile a present |
|
| 107 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 108 | - $skel_code[$id] = $f; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $code = ''; |
|
| 112 | - if ($nom) { |
|
| 113 | - // Si le code est bon, concatener et mettre en cache |
|
| 114 | - if (function_exists($nom)) { |
|
| 115 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 116 | - } else { |
|
| 117 | - // code semantiquement faux: bug du compilateur |
|
| 118 | - // $boucle est en fait ici la fct principale du squelette |
|
| 119 | - $msg = _T('zbug_erreur_compilation'); |
|
| 120 | - erreur_squelette($msg, $boucle); |
|
| 121 | - $nom = ''; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - if (defined('_VAR_MODE') && _VAR_MODE == 'debug') { |
|
| 126 | - // Tracer ce qui vient d'etre compile |
|
| 127 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 128 | - |
|
| 129 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 130 | - if ( |
|
| 131 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 132 | - && _request('var_mode_objet') == $nom |
|
| 133 | - && _request('var_mode_affiche') == 'code' |
|
| 134 | - ) { |
|
| 135 | - erreur_squelette(); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $nom ?: false; |
|
| 45 | + $skel = null; |
|
| 46 | + $boucle = null; |
|
| 47 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 48 | + |
|
| 49 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 50 | + if (function_exists($nom)) { |
|
| 51 | + return $nom; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (defined('_VAR_MODE') && _VAR_MODE == 'debug') { |
|
| 55 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 59 | + |
|
| 60 | + // si squelette est deja compile et perenne, le charger |
|
| 61 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 62 | + include_once $phpfile; |
|
| 63 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 64 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 65 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 66 | + ## eval('?'.'>'.$skel_code); |
|
| 67 | + # spip_logger('comp')->info($skel_code); |
|
| 68 | + #} |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 72 | + include_once $lib; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 76 | + |
|
| 77 | + if (function_exists($nom)) { |
|
| 78 | + return $nom; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // charger le source, si possible, et compiler |
|
| 82 | + $skel_code = ''; |
|
| 83 | + if (lire_fichier($source, $skel)) { |
|
| 84 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 85 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 89 | + if (!$skel_code) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + foreach ($skel_code as $id => $boucle) { |
|
| 94 | + $f = $boucle->return; |
|
| 95 | + try { |
|
| 96 | + eval("return true; $f ;"); |
|
| 97 | + } catch (\ParseError $e) { |
|
| 98 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 99 | + $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 100 | + erreur_squelette($msg, $boucle); |
|
| 101 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 102 | + // mais prevenir que c'est mort |
|
| 103 | + $nom = ''; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // contexte de compil inutile a present |
|
| 107 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 108 | + $skel_code[$id] = $f; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $code = ''; |
|
| 112 | + if ($nom) { |
|
| 113 | + // Si le code est bon, concatener et mettre en cache |
|
| 114 | + if (function_exists($nom)) { |
|
| 115 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 116 | + } else { |
|
| 117 | + // code semantiquement faux: bug du compilateur |
|
| 118 | + // $boucle est en fait ici la fct principale du squelette |
|
| 119 | + $msg = _T('zbug_erreur_compilation'); |
|
| 120 | + erreur_squelette($msg, $boucle); |
|
| 121 | + $nom = ''; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + if (defined('_VAR_MODE') && _VAR_MODE == 'debug') { |
|
| 126 | + // Tracer ce qui vient d'etre compile |
|
| 127 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 128 | + |
|
| 129 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 130 | + if ( |
|
| 131 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 132 | + && _request('var_mode_objet') == $nom |
|
| 133 | + && _request('var_mode_affiche') == 'code' |
|
| 134 | + ) { |
|
| 135 | + erreur_squelette(); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $nom ?: false; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 143 | 143 | |
| 144 | - $code = null; |
|
| 145 | - // Le dernier index est '' (fonction principale) |
|
| 146 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 147 | - if (CODE_COMMENTE) { |
|
| 148 | - $code = " |
|
| 144 | + $code = null; |
|
| 145 | + // Le dernier index est '' (fonction principale) |
|
| 146 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 147 | + if (CODE_COMMENTE) { |
|
| 148 | + $code = " |
|
| 149 | 149 | /* |
| 150 | 150 | * Squelette : $sourcefile |
| 151 | 151 | * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
| 152 | 152 | * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
| 153 | 153 | * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
| 154 | 154 | */ '; |
| 155 | - } |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 158 | - if (!defined('_VAR_NOCACHE') || !_VAR_NOCACHE) { |
|
| 159 | - ecrire_fichier($phpfile, $code); |
|
| 160 | - } |
|
| 157 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 158 | + if (!defined('_VAR_NOCACHE') || !_VAR_NOCACHE) { |
|
| 159 | + ecrire_fichier($phpfile, $code); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $code; |
|
| 162 | + return $code; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Le squelette compile est-il trop vieux ? |
| 166 | 166 | function squelette_obsolete($skel, $squelette) { |
| 167 | - static $date_change = null; |
|
| 168 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 169 | - // par hit |
|
| 170 | - if (is_null($date_change)) { |
|
| 171 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 172 | - $date_change = @filemtime($fonc); |
|
| 173 | - } # compatibilite |
|
| 174 | - if (defined('_FILE_OPTIONS')) { |
|
| 175 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return ( |
|
| 180 | - defined('_VAR_MODE') && in_array(_VAR_MODE, ['recalcul', 'preview', 'debug']) |
|
| 181 | - || !@file_exists($skel) |
|
| 182 | - || (@file_exists($squelette) ? @filemtime($squelette) : 0) > ($date = @filemtime($skel)) |
|
| 183 | - || $date_change > $date |
|
| 184 | - ); |
|
| 167 | + static $date_change = null; |
|
| 168 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 169 | + // par hit |
|
| 170 | + if (is_null($date_change)) { |
|
| 171 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 172 | + $date_change = @filemtime($fonc); |
|
| 173 | + } # compatibilite |
|
| 174 | + if (defined('_FILE_OPTIONS')) { |
|
| 175 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return ( |
|
| 180 | + defined('_VAR_MODE') && in_array(_VAR_MODE, ['recalcul', 'preview', 'debug']) |
|
| 181 | + || !@file_exists($skel) |
|
| 182 | + || (@file_exists($squelette) ? @filemtime($squelette) : 0) > ($date = @filemtime($skel)) |
|
| 183 | + || $date_change > $date |
|
| 184 | + ); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Activer l'invalideur de session |
| 188 | 188 | function invalideur_session(&$Cache, $code = null) { |
| 189 | - $Cache['session'] = spip_session(); |
|
| 189 | + $Cache['session'] = spip_session(); |
|
| 190 | 190 | |
| 191 | - return $code; |
|
| 191 | + return $code; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
| 195 | 195 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 196 | - static $filtres = []; |
|
| 197 | - $headers = []; |
|
| 198 | - $corps ??= ''; |
|
| 199 | - |
|
| 200 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | - if ( |
|
| 204 | - stripos($corps, 'header') !== false |
|
| 205 | - && preg_match_all( |
|
| 206 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | - $corps, |
|
| 208 | - $regs, |
|
| 209 | - PREG_SET_ORDER |
|
| 210 | - ) |
|
| 211 | - ) { |
|
| 212 | - foreach ($regs as $r) { |
|
| 213 | - $corps = str_replace($r[0], '', $corps); |
|
| 214 | - # $j = Content-Type, et pas content-TYPE. |
|
| 215 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | - |
|
| 217 | - if ($j == 'X-Spip-Filtre' && isset($headers[$j])) { |
|
| 218 | - $headers[$j] .= '|' . $r[3]; |
|
| 219 | - } else { |
|
| 220 | - $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | - $process_ins = ( |
|
| 226 | - !str_contains($corps, '<' . '?') |
|
| 227 | - || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 228 | - ) |
|
| 229 | - ? 'html' |
|
| 230 | - : 'php'; |
|
| 231 | - |
|
| 232 | - $skel = [ |
|
| 233 | - 'squelette' => $nom, |
|
| 234 | - 'source' => $source, |
|
| 235 | - 'process_ins' => $process_ins, |
|
| 236 | - 'invalideurs' => $cache, |
|
| 237 | - 'entetes' => $headers, |
|
| 238 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 239 | - ]; |
|
| 240 | - |
|
| 241 | - // traiter #FILTRE{} et filtres |
|
| 242 | - if (!isset($filtres[$nom])) { |
|
| 243 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 244 | - } |
|
| 245 | - $filtres_headers = []; |
|
| 246 | - if (isset($headers['X-Spip-Filtre']) && strlen($headers['X-Spip-Filtre'])) { |
|
| 247 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 248 | - unset($headers['X-Spip-Filtre']); |
|
| 249 | - } |
|
| 250 | - if ((is_countable($filtres[$nom]) ? count($filtres[$nom]) : 0) || count($filtres_headers)) { |
|
| 251 | - include_spip('public/sandbox'); |
|
| 252 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 253 | - |
|
| 254 | - if ($process_ins == 'html') { |
|
| 255 | - $skel['process_ins'] = ( |
|
| 256 | - !str_contains($corps, '<' . '?') |
|
| 257 | - || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 258 | - ) |
|
| 259 | - ? 'html' |
|
| 260 | - : 'php'; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $skel['entetes'] = $headers; |
|
| 265 | - $skel['texte'] = $corps; |
|
| 266 | - |
|
| 267 | - return $skel; |
|
| 196 | + static $filtres = []; |
|
| 197 | + $headers = []; |
|
| 198 | + $corps ??= ''; |
|
| 199 | + |
|
| 200 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | + if ( |
|
| 204 | + stripos($corps, 'header') !== false |
|
| 205 | + && preg_match_all( |
|
| 206 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | + $corps, |
|
| 208 | + $regs, |
|
| 209 | + PREG_SET_ORDER |
|
| 210 | + ) |
|
| 211 | + ) { |
|
| 212 | + foreach ($regs as $r) { |
|
| 213 | + $corps = str_replace($r[0], '', $corps); |
|
| 214 | + # $j = Content-Type, et pas content-TYPE. |
|
| 215 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | + |
|
| 217 | + if ($j == 'X-Spip-Filtre' && isset($headers[$j])) { |
|
| 218 | + $headers[$j] .= '|' . $r[3]; |
|
| 219 | + } else { |
|
| 220 | + $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | + $process_ins = ( |
|
| 226 | + !str_contains($corps, '<' . '?') |
|
| 227 | + || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 228 | + ) |
|
| 229 | + ? 'html' |
|
| 230 | + : 'php'; |
|
| 231 | + |
|
| 232 | + $skel = [ |
|
| 233 | + 'squelette' => $nom, |
|
| 234 | + 'source' => $source, |
|
| 235 | + 'process_ins' => $process_ins, |
|
| 236 | + 'invalideurs' => $cache, |
|
| 237 | + 'entetes' => $headers, |
|
| 238 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 239 | + ]; |
|
| 240 | + |
|
| 241 | + // traiter #FILTRE{} et filtres |
|
| 242 | + if (!isset($filtres[$nom])) { |
|
| 243 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 244 | + } |
|
| 245 | + $filtres_headers = []; |
|
| 246 | + if (isset($headers['X-Spip-Filtre']) && strlen($headers['X-Spip-Filtre'])) { |
|
| 247 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 248 | + unset($headers['X-Spip-Filtre']); |
|
| 249 | + } |
|
| 250 | + if ((is_countable($filtres[$nom]) ? count($filtres[$nom]) : 0) || count($filtres_headers)) { |
|
| 251 | + include_spip('public/sandbox'); |
|
| 252 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 253 | + |
|
| 254 | + if ($process_ins == 'html') { |
|
| 255 | + $skel['process_ins'] = ( |
|
| 256 | + !str_contains($corps, '<' . '?') |
|
| 257 | + || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 258 | + ) |
|
| 259 | + ? 'html' |
|
| 260 | + : 'php'; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $skel['entetes'] = $headers; |
|
| 265 | + $skel['texte'] = $corps; |
|
| 266 | + |
|
| 267 | + return $skel; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 279 | 279 | if ($lang_select) lang_select(); |
| 280 | 280 | ?' |
| 281 | - . '>'); |
|
| 281 | + . '>'); |
|
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | 284 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -298,35 +298,35 @@ discard block |
||
| 298 | 298 | * Code PHP pour inclure le squelette de la balise dynamique |
| 299 | 299 | **/ |
| 300 | 300 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 301 | - if ( |
|
| 302 | - !str_starts_with($file, '/') |
|
| 303 | - // pas de lien symbolique sous Windows |
|
| 304 | - && !(stristr(PHP_OS, 'WIN') && str_contains($file, ':')) |
|
| 305 | - ) { |
|
| 306 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $lang = $context_compil[4]; |
|
| 310 | - if (preg_match(',\W,', $lang)) { |
|
| 311 | - $lang = ''; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $args = array_map('argumenter_squelette', $args); |
|
| 315 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 316 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 317 | - } |
|
| 318 | - $args = join(', ', $args); |
|
| 319 | - |
|
| 320 | - $r = sprintf( |
|
| 321 | - CODE_INCLURE_BALISE, |
|
| 322 | - $file, |
|
| 323 | - $lang, |
|
| 324 | - $nom, |
|
| 325 | - $args, |
|
| 326 | - join(', ', array_map('_q', $context_compil)) |
|
| 327 | - ); |
|
| 328 | - |
|
| 329 | - return $r; |
|
| 301 | + if ( |
|
| 302 | + !str_starts_with($file, '/') |
|
| 303 | + // pas de lien symbolique sous Windows |
|
| 304 | + && !(stristr(PHP_OS, 'WIN') && str_contains($file, ':')) |
|
| 305 | + ) { |
|
| 306 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $lang = $context_compil[4]; |
|
| 310 | + if (preg_match(',\W,', $lang)) { |
|
| 311 | + $lang = ''; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $args = array_map('argumenter_squelette', $args); |
|
| 315 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 316 | + $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 317 | + } |
|
| 318 | + $args = join(', ', $args); |
|
| 319 | + |
|
| 320 | + $r = sprintf( |
|
| 321 | + CODE_INCLURE_BALISE, |
|
| 322 | + $file, |
|
| 323 | + $lang, |
|
| 324 | + $nom, |
|
| 325 | + $args, |
|
| 326 | + join(', ', array_map('_q', $context_compil)) |
|
| 327 | + ); |
|
| 328 | + |
|
| 329 | + return $r; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -344,18 +344,18 @@ discard block |
||
| 344 | 344 | **/ |
| 345 | 345 | function argumenter_squelette($v) { |
| 346 | 346 | |
| 347 | - if (is_object($v)) { |
|
| 348 | - return var_export($v, true); |
|
| 349 | - } elseif (!is_array($v)) { |
|
| 350 | - return "'" . texte_script((string) $v) . "'"; |
|
| 351 | - } else { |
|
| 352 | - $out = []; |
|
| 353 | - foreach ($v as $k => $val) { |
|
| 354 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - return 'array(' . join(', ', $out) . ')'; |
|
| 358 | - } |
|
| 347 | + if (is_object($v)) { |
|
| 348 | + return var_export($v, true); |
|
| 349 | + } elseif (!is_array($v)) { |
|
| 350 | + return "'" . texte_script((string) $v) . "'"; |
|
| 351 | + } else { |
|
| 352 | + $out = []; |
|
| 353 | + foreach ($v as $k => $val) { |
|
| 354 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + return 'array(' . join(', ', $out) . ')'; |
|
| 358 | + } |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -374,13 +374,13 @@ discard block |
||
| 374 | 374 | * @return string |
| 375 | 375 | */ |
| 376 | 376 | function executer_balise_dynamique_dans_un_modele(...$args) { |
| 377 | - if (test_espace_prive()) { |
|
| 378 | - return executer_balise_dynamique(...$args); |
|
| 379 | - } |
|
| 380 | - else { |
|
| 381 | - $str_args = base64_encode(serialize($args)); |
|
| 382 | - return '<?' . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?" . ">\n"; |
|
| 383 | - } |
|
| 377 | + if (test_espace_prive()) { |
|
| 378 | + return executer_balise_dynamique(...$args); |
|
| 379 | + } |
|
| 380 | + else { |
|
| 381 | + $str_args = base64_encode(serialize($args)); |
|
| 382 | + return '<?' . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?" . ">\n"; |
|
| 383 | + } |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | |
@@ -411,87 +411,87 @@ discard block |
||
| 411 | 411 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 412 | 412 | **/ |
| 413 | 413 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 414 | - /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 415 | - $nom_balise = $nom; |
|
| 416 | - /** @var string Nom de la balise générique (si utilisée) */ |
|
| 417 | - $nom_balise_generique = ''; |
|
| 418 | - |
|
| 419 | - $appel_php_depuis_modele = false; |
|
| 420 | - if ( |
|
| 421 | - is_array($context_compil) |
|
| 422 | - && !is_numeric($context_compil[3]) |
|
| 423 | - && empty($context_compil[0]) |
|
| 424 | - && empty($context_compil[1]) |
|
| 425 | - && empty($context_compil[2]) |
|
| 426 | - && empty($context_compil[3]) |
|
| 427 | - ) { |
|
| 428 | - $appel_php_depuis_modele = true; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 432 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 433 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 434 | - // injecter en premier arg le nom de la balise |
|
| 435 | - array_unshift($args, $nom); |
|
| 436 | - $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 437 | - $fonction_balise = $balise_generique['fonction_generique']; |
|
| 438 | - $nom_balise = $nom_balise_generique; |
|
| 439 | - } |
|
| 440 | - unset($balise_generique); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - if (!$fonction_balise) { |
|
| 444 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 445 | - erreur_squelette($msg, $context_compil); |
|
| 446 | - |
|
| 447 | - return ''; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - // retrouver le fichier qui a déclaré la fonction |
|
| 451 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 452 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 453 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 454 | - $file = $reflector->getFileName(); |
|
| 455 | - if (str_starts_with($file, _ROOT_RACINE)) { |
|
| 456 | - $file = str_replace(\DIRECTORY_SEPARATOR, '/', substr($file, strlen(_ROOT_RACINE))); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 460 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 461 | - |
|
| 462 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 463 | - |
|
| 464 | - if (!is_array($r)) { |
|
| 465 | - return $r; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // verifier que la fonction dyn est la, |
|
| 469 | - // sinon se replier sur la generique si elle existe |
|
| 470 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 471 | - if ( |
|
| 472 | - ($balise_generique = chercher_balise_generique($nom)) |
|
| 473 | - && ($nom_balise_generique = $balise_generique['nom_generique']) |
|
| 474 | - && ($file = include_spip('balise/' . strtolower($nom_balise_generique))) |
|
| 475 | - && function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 476 | - ) { |
|
| 477 | - // et lui injecter en premier arg le nom de la balise |
|
| 478 | - array_unshift($r, $nom); |
|
| 479 | - $nom_balise = $nom_balise_generique; |
|
| 480 | - if (!_DIR_RESTREINT) { |
|
| 481 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 482 | - } |
|
| 483 | - } else { |
|
| 484 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 485 | - erreur_squelette($msg, $context_compil); |
|
| 486 | - |
|
| 487 | - return ''; |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - if ($appel_php_depuis_modele) { |
|
| 492 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 493 | - } |
|
| 494 | - return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 414 | + /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 415 | + $nom_balise = $nom; |
|
| 416 | + /** @var string Nom de la balise générique (si utilisée) */ |
|
| 417 | + $nom_balise_generique = ''; |
|
| 418 | + |
|
| 419 | + $appel_php_depuis_modele = false; |
|
| 420 | + if ( |
|
| 421 | + is_array($context_compil) |
|
| 422 | + && !is_numeric($context_compil[3]) |
|
| 423 | + && empty($context_compil[0]) |
|
| 424 | + && empty($context_compil[1]) |
|
| 425 | + && empty($context_compil[2]) |
|
| 426 | + && empty($context_compil[3]) |
|
| 427 | + ) { |
|
| 428 | + $appel_php_depuis_modele = true; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 432 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 433 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 434 | + // injecter en premier arg le nom de la balise |
|
| 435 | + array_unshift($args, $nom); |
|
| 436 | + $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 437 | + $fonction_balise = $balise_generique['fonction_generique']; |
|
| 438 | + $nom_balise = $nom_balise_generique; |
|
| 439 | + } |
|
| 440 | + unset($balise_generique); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + if (!$fonction_balise) { |
|
| 444 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 445 | + erreur_squelette($msg, $context_compil); |
|
| 446 | + |
|
| 447 | + return ''; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + // retrouver le fichier qui a déclaré la fonction |
|
| 451 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 452 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 453 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 454 | + $file = $reflector->getFileName(); |
|
| 455 | + if (str_starts_with($file, _ROOT_RACINE)) { |
|
| 456 | + $file = str_replace(\DIRECTORY_SEPARATOR, '/', substr($file, strlen(_ROOT_RACINE))); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 460 | + $f = 'balise_' . $nom_balise . '_stat'; |
|
| 461 | + |
|
| 462 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 463 | + |
|
| 464 | + if (!is_array($r)) { |
|
| 465 | + return $r; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // verifier que la fonction dyn est la, |
|
| 469 | + // sinon se replier sur la generique si elle existe |
|
| 470 | + if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 471 | + if ( |
|
| 472 | + ($balise_generique = chercher_balise_generique($nom)) |
|
| 473 | + && ($nom_balise_generique = $balise_generique['nom_generique']) |
|
| 474 | + && ($file = include_spip('balise/' . strtolower($nom_balise_generique))) |
|
| 475 | + && function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 476 | + ) { |
|
| 477 | + // et lui injecter en premier arg le nom de la balise |
|
| 478 | + array_unshift($r, $nom); |
|
| 479 | + $nom_balise = $nom_balise_generique; |
|
| 480 | + if (!_DIR_RESTREINT) { |
|
| 481 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 482 | + } |
|
| 483 | + } else { |
|
| 484 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 485 | + erreur_squelette($msg, $context_compil); |
|
| 486 | + |
|
| 487 | + return ''; |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + if ($appel_php_depuis_modele) { |
|
| 492 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 493 | + } |
|
| 494 | + return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -506,23 +506,23 @@ discard block |
||
| 506 | 506 | * @return array|null |
| 507 | 507 | */ |
| 508 | 508 | function chercher_balise_generique($nom) { |
| 509 | - if (!str_contains($nom, '_')) { |
|
| 510 | - return null; |
|
| 511 | - } |
|
| 512 | - $nom_generique = $nom; |
|
| 513 | - while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 514 | - $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 515 | - $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 516 | - if ($fonction_generique) { |
|
| 517 | - return [ |
|
| 518 | - 'nom' => $nom, |
|
| 519 | - 'nom_generique' => $nom_generique, |
|
| 520 | - 'fonction_generique' => $fonction_generique, |
|
| 521 | - ]; |
|
| 522 | - } |
|
| 523 | - $nom_generique = substr($nom_generique, 0, -1); |
|
| 524 | - } |
|
| 525 | - return null; |
|
| 509 | + if (!str_contains($nom, '_')) { |
|
| 510 | + return null; |
|
| 511 | + } |
|
| 512 | + $nom_generique = $nom; |
|
| 513 | + while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 514 | + $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 515 | + $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 516 | + if ($fonction_generique) { |
|
| 517 | + return [ |
|
| 518 | + 'nom' => $nom, |
|
| 519 | + 'nom_generique' => $nom_generique, |
|
| 520 | + 'fonction_generique' => $fonction_generique, |
|
| 521 | + ]; |
|
| 522 | + } |
|
| 523 | + $nom_generique = substr($nom_generique, 0, -1); |
|
| 524 | + } |
|
| 525 | + return null; |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | |
@@ -546,51 +546,51 @@ discard block |
||
| 546 | 546 | * @return null; |
| 547 | 547 | **/ |
| 548 | 548 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 549 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 550 | - if ( |
|
| 551 | - isset($GLOBALS['forcer_lang']) |
|
| 552 | - && $GLOBALS['forcer_lang'] |
|
| 553 | - && $lang_select !== 'oui' |
|
| 554 | - ) { |
|
| 555 | - $lang = $GLOBALS['spip_lang']; |
|
| 556 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 557 | - elseif (!strlen($lang)) { |
|
| 558 | - $lang = $GLOBALS['spip_lang']; |
|
| 559 | - } // Cas 3. l'objet est multilingue ! |
|
| 560 | - elseif ( |
|
| 561 | - $lang_select !== 'oui' |
|
| 562 | - && strlen($titre) > 10 |
|
| 563 | - && str_contains($titre, '<multi>') |
|
| 564 | - && str_contains(CollecteurHtmlTag::proteger_balisesHtml($titre), '<multi>') |
|
| 565 | - ) { |
|
| 566 | - $lang = $GLOBALS['spip_lang']; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 570 | - lang_select($lang); |
|
| 571 | - |
|
| 572 | - return; |
|
| 549 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 550 | + if ( |
|
| 551 | + isset($GLOBALS['forcer_lang']) |
|
| 552 | + && $GLOBALS['forcer_lang'] |
|
| 553 | + && $lang_select !== 'oui' |
|
| 554 | + ) { |
|
| 555 | + $lang = $GLOBALS['spip_lang']; |
|
| 556 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 557 | + elseif (!strlen($lang)) { |
|
| 558 | + $lang = $GLOBALS['spip_lang']; |
|
| 559 | + } // Cas 3. l'objet est multilingue ! |
|
| 560 | + elseif ( |
|
| 561 | + $lang_select !== 'oui' |
|
| 562 | + && strlen($titre) > 10 |
|
| 563 | + && str_contains($titre, '<multi>') |
|
| 564 | + && str_contains(CollecteurHtmlTag::proteger_balisesHtml($titre), '<multi>') |
|
| 565 | + ) { |
|
| 566 | + $lang = $GLOBALS['spip_lang']; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 570 | + lang_select($lang); |
|
| 571 | + |
|
| 572 | + return; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | |
| 576 | 576 | // Si un tableau &doublons[articles] est passe en parametre, |
| 577 | 577 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 578 | 578 | function nettoyer_env_doublons($envd) { |
| 579 | - foreach ($envd as $table => $liste) { |
|
| 580 | - $n = ''; |
|
| 581 | - foreach (explode(',', $liste) as $val) { |
|
| 582 | - if (($a = intval($val)) && $val === strval($a)) { |
|
| 583 | - $n .= ',' . $val; |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - if (strlen($n)) { |
|
| 587 | - $envd[$table] = $n; |
|
| 588 | - } else { |
|
| 589 | - unset($envd[$table]); |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - return $envd; |
|
| 579 | + foreach ($envd as $table => $liste) { |
|
| 580 | + $n = ''; |
|
| 581 | + foreach (explode(',', $liste) as $val) { |
|
| 582 | + if (($a = intval($val)) && $val === strval($a)) { |
|
| 583 | + $n .= ',' . $val; |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + if (strlen($n)) { |
|
| 587 | + $envd[$table] = $n; |
|
| 588 | + } else { |
|
| 589 | + unset($envd[$table]); |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + return $envd; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -609,21 +609,21 @@ discard block |
||
| 609 | 609 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 610 | 610 | **/ |
| 611 | 611 | function match_self($w) { |
| 612 | - if (is_string($w)) { |
|
| 613 | - return false; |
|
| 614 | - } |
|
| 615 | - if (is_array($w)) { |
|
| 616 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 617 | - return $w; |
|
| 618 | - } |
|
| 619 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 620 | - if ($m = match_self($sw)) { |
|
| 621 | - return $m; |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - return false; |
|
| 612 | + if (is_string($w)) { |
|
| 613 | + return false; |
|
| 614 | + } |
|
| 615 | + if (is_array($w)) { |
|
| 616 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 617 | + return $w; |
|
| 618 | + } |
|
| 619 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 620 | + if ($m = match_self($sw)) { |
|
| 621 | + return $m; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + return false; |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | /** |
@@ -639,16 +639,16 @@ discard block |
||
| 639 | 639 | * est remplacée par son code. |
| 640 | 640 | **/ |
| 641 | 641 | function remplace_sous_requete($w, $sousrequete) { |
| 642 | - if (is_array($w)) { |
|
| 643 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 644 | - return $sousrequete; |
|
| 645 | - } |
|
| 646 | - foreach ($w as $k => $sw) { |
|
| 647 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - return $w; |
|
| 642 | + if (is_array($w)) { |
|
| 643 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 644 | + return $sousrequete; |
|
| 645 | + } |
|
| 646 | + foreach ($w as $k => $sw) { |
|
| 647 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + return $w; |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | /** |
@@ -662,17 +662,17 @@ discard block |
||
| 662 | 662 | * - Conditions avec des sous requêtes |
| 663 | 663 | **/ |
| 664 | 664 | function trouver_sous_requetes($where) { |
| 665 | - $where_simples = []; |
|
| 666 | - $where_sous = []; |
|
| 667 | - foreach ($where as $k => $w) { |
|
| 668 | - if (match_self($w)) { |
|
| 669 | - $where_sous[$k] = $w; |
|
| 670 | - } else { |
|
| 671 | - $where_simples[$k] = $w; |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - return [$where_simples, $where_sous]; |
|
| 665 | + $where_simples = []; |
|
| 666 | + $where_sous = []; |
|
| 667 | + foreach ($where as $k => $w) { |
|
| 668 | + if (match_self($w)) { |
|
| 669 | + $where_sous[$k] = $w; |
|
| 670 | + } else { |
|
| 671 | + $where_simples[$k] = $w; |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + return [$where_simples, $where_sous]; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | |
@@ -698,293 +698,293 @@ discard block |
||
| 698 | 698 | * @return resource |
| 699 | 699 | */ |
| 700 | 700 | function calculer_select( |
| 701 | - $select = [], |
|
| 702 | - $from = [], |
|
| 703 | - $from_type = [], |
|
| 704 | - $where = [], |
|
| 705 | - $join = [], |
|
| 706 | - $groupby = [], |
|
| 707 | - $orderby = [], |
|
| 708 | - $limit = '', |
|
| 709 | - $having = [], |
|
| 710 | - $table = '', |
|
| 711 | - $id = '', |
|
| 712 | - $serveur = '', |
|
| 713 | - $requeter = true |
|
| 701 | + $select = [], |
|
| 702 | + $from = [], |
|
| 703 | + $from_type = [], |
|
| 704 | + $where = [], |
|
| 705 | + $join = [], |
|
| 706 | + $groupby = [], |
|
| 707 | + $orderby = [], |
|
| 708 | + $limit = '', |
|
| 709 | + $having = [], |
|
| 710 | + $table = '', |
|
| 711 | + $id = '', |
|
| 712 | + $serveur = '', |
|
| 713 | + $requeter = true |
|
| 714 | 714 | ) { |
| 715 | 715 | |
| 716 | - // retirer les criteres vides: |
|
| 717 | - // {X ?} avec X absent de l'URL |
|
| 718 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 719 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 720 | - $menage = false; |
|
| 721 | - foreach ($where as $k => $v) { |
|
| 722 | - if (is_array($v) && count($v)) { |
|
| 723 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 724 | - $op = false; |
|
| 725 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 726 | - $op = false; |
|
| 727 | - } else { |
|
| 728 | - $op = $v[0] ?: $v; |
|
| 729 | - } |
|
| 730 | - } else { |
|
| 731 | - $op = $v; |
|
| 732 | - } |
|
| 733 | - if (!$op || $op == 1 || $op == '0=0') { |
|
| 734 | - unset($where[$k]); |
|
| 735 | - $menage = true; |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 740 | - $groupby = array_diff($groupby, ['']); |
|
| 741 | - |
|
| 742 | - // remplacer les sous requetes recursives au calcul |
|
| 743 | - [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 744 | - foreach ($where_sous as $k => $w) { |
|
| 745 | - $menage = true; |
|
| 746 | - // on recupere la sous requete |
|
| 747 | - $sous = match_self($w); |
|
| 748 | - if ($sous[0] == 'SELF') { |
|
| 749 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 750 | - array_push($where_simples, $sous[2]); |
|
| 751 | - $wheresub = [ |
|
| 752 | - $sous[2], |
|
| 753 | - '0=0' |
|
| 754 | - ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 755 | - $jsub = $join; |
|
| 756 | - // trouver les jointures utiles a |
|
| 757 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 758 | - // ie L1.objet='article' |
|
| 759 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 760 | - $i = 0; |
|
| 761 | - do { |
|
| 762 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 763 | - [$sous[1] . ' AS id'], |
|
| 764 | - $from, |
|
| 765 | - $from_type, |
|
| 766 | - $wheresub, |
|
| 767 | - $jsub, |
|
| 768 | - [], |
|
| 769 | - [], |
|
| 770 | - '', |
|
| 771 | - $having, |
|
| 772 | - $table, |
|
| 773 | - $id, |
|
| 774 | - $serveur, |
|
| 775 | - false |
|
| 776 | - ) . ')'); |
|
| 777 | - if (!$i) { |
|
| 778 | - $i = 1; |
|
| 779 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 780 | - foreach ($join as $cle => $wj) { |
|
| 781 | - if ( |
|
| 782 | - (is_countable($wj) ? count($wj) : 0) == 4 && str_contains($wherestring, (string) "{$cle}.") |
|
| 783 | - ) { |
|
| 784 | - $i = 0; |
|
| 785 | - $wheresub[] = $wj[3]; |
|
| 786 | - unset($jsub[$cle][3]); |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - } while ($i++ < 1); |
|
| 791 | - } |
|
| 792 | - if ($sous[0] == 'SUBSELECT') { |
|
| 793 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 794 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 795 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 796 | - $sous[1], # select |
|
| 797 | - $sous[2], #from |
|
| 798 | - [], #from_type |
|
| 799 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 800 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 801 | - [], #join |
|
| 802 | - $sous[4] ?: [], #groupby |
|
| 803 | - $sous[5] ?: [], #orderby |
|
| 804 | - $sous[6], #limit |
|
| 805 | - $sous[7] ?: [], #having |
|
| 806 | - $table, |
|
| 807 | - $id, |
|
| 808 | - $serveur, |
|
| 809 | - false |
|
| 810 | - ) . ')'); |
|
| 811 | - } |
|
| 812 | - array_pop($where_simples); |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - foreach ($having as $k => $v) { |
|
| 816 | - if (!$v || $v == 1 || $v == '0=0') { |
|
| 817 | - unset($having[$k]); |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - // Installer les jointures. |
|
| 822 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 823 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 824 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 825 | - |
|
| 826 | - $afrom = []; |
|
| 827 | - $equiv = []; |
|
| 828 | - $k = count($join); |
|
| 829 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 830 | - $cle = $cledef; |
|
| 831 | - // le format de join est : |
|
| 832 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 833 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 834 | - if (count($join[$cle]) == 2) { |
|
| 835 | - $join[$cle][] = $join[$cle][1]; |
|
| 836 | - } |
|
| 837 | - if ((is_countable($join[$cle]) ? count($join[$cle]) : 0) == 3) { |
|
| 838 | - $join[$cle][] = ''; |
|
| 839 | - } |
|
| 840 | - [$t, $c, $carr, $and] = $join[$cle]; |
|
| 841 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 842 | - // pour compat avec ancienne convention |
|
| 843 | - if (is_numeric($cle)) { |
|
| 844 | - $cle = "L$k"; |
|
| 845 | - } |
|
| 846 | - $cle_where_lie = "JOIN-$cle"; |
|
| 847 | - if ( |
|
| 848 | - !$menage |
|
| 849 | - || isset($afrom[$cle]) |
|
| 850 | - || calculer_jointnul($cle, $select) |
|
| 851 | - || calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 852 | - || calculer_jointnul($cle, $having) |
|
| 853 | - || calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 854 | - ) { |
|
| 855 | - // corriger les references non explicites dans select |
|
| 856 | - // ou groupby |
|
| 857 | - foreach ($select as $i => $s) { |
|
| 858 | - if ($s == $c) { |
|
| 859 | - $select[$i] = "$cle.$c AS $c"; |
|
| 860 | - break; |
|
| 861 | - } |
|
| 862 | - } |
|
| 863 | - foreach ($groupby as $i => $g) { |
|
| 864 | - if ($g == $c) { |
|
| 865 | - $groupby[$i] = "$cle.$c"; |
|
| 866 | - break; |
|
| 867 | - } |
|
| 868 | - } |
|
| 869 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 870 | - // sans recours a preg_match |
|
| 871 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 872 | - $afrom[$t][$cle] = [ |
|
| 873 | - "\n" . |
|
| 874 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 875 | - $from[$cle], |
|
| 876 | - "AS $cle", |
|
| 877 | - 'ON (', |
|
| 878 | - "$cle.$c", |
|
| 879 | - '=', |
|
| 880 | - "$t.$carr", |
|
| 881 | - ($and ? 'AND ' . $and : '') . |
|
| 882 | - ')' |
|
| 883 | - ]; |
|
| 884 | - if (isset($afrom[$cle])) { |
|
| 885 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 886 | - unset($afrom[$cle]); |
|
| 887 | - } |
|
| 888 | - $equiv[] = $carr; |
|
| 889 | - } else { |
|
| 890 | - unset($join[$cledef]); |
|
| 891 | - if (isset($where_simples[$cle_where_lie])) { |
|
| 892 | - unset($where_simples[$cle_where_lie]); |
|
| 893 | - unset($where[$cle_where_lie]); |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - unset($from[$cle]); |
|
| 897 | - $k--; |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - if (count($afrom)) { |
|
| 901 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 902 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 903 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 904 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 905 | - // ou dans |
|
| 906 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 907 | - // qui comporte plusieurs jointures |
|
| 908 | - // ou dans |
|
| 909 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 910 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 911 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 912 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 913 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 914 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 915 | - |
|
| 916 | - $t = key($from); |
|
| 917 | - $c = current($from); |
|
| 918 | - reset($from); |
|
| 919 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 920 | - if ( |
|
| 921 | - !( |
|
| 922 | - strpos($t, ' ') |
|
| 923 | - // jointure des le depart cf boucle_doc |
|
| 924 | - || calculer_jointnul($t, $select, $e) |
|
| 925 | - || calculer_jointnul($t, $join, $e) |
|
| 926 | - || calculer_jointnul($t, $where, $e) |
|
| 927 | - || calculer_jointnul($t, $orderby, $e) |
|
| 928 | - || calculer_jointnul($t, $groupby, $e) || calculer_jointnul($t, $having, $e) |
|
| 929 | - ) |
|
| 930 | - && count($afrom[$t]) |
|
| 931 | - ) { |
|
| 932 | - $nfrom = reset($afrom[$t]); |
|
| 933 | - $nt = array_key_first($afrom[$t]); |
|
| 934 | - unset($from[$t]); |
|
| 935 | - $from[$nt] = $nfrom[1]; |
|
| 936 | - unset($afrom[$t][$nt]); |
|
| 937 | - $afrom[$nt] = $afrom[$t]; |
|
| 938 | - unset($afrom[$t]); |
|
| 939 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 940 | - $t = $nfrom[4]; |
|
| 941 | - $alias = ''; |
|
| 942 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 943 | - $oldcle = explode('.', $nfrom[6]); |
|
| 944 | - $oldcle = end($oldcle); |
|
| 945 | - $newcle = explode('.', $nfrom[4]); |
|
| 946 | - $newcle = end($newcle); |
|
| 947 | - if ($newcle != $oldcle) { |
|
| 948 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 949 | - // reprendre simplement ce AS |
|
| 950 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 951 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 952 | - $alias = ''; |
|
| 953 | - } else { |
|
| 954 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 958 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 959 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 960 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 961 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 962 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 963 | - } |
|
| 964 | - $from = reinjecte_joint($afrom, $from); |
|
| 965 | - } |
|
| 966 | - if (empty($GLOBALS['debug']) || !is_array($GLOBALS['debug'])) { |
|
| 967 | - $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 968 | - $GLOBALS['debug'] = []; |
|
| 969 | - if ($wasdebug) { |
|
| 970 | - $GLOBALS['debug']['debug'] = true; |
|
| 971 | - } |
|
| 972 | - } |
|
| 973 | - $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 974 | - $r = sql_select( |
|
| 975 | - $select, |
|
| 976 | - $from, |
|
| 977 | - $where, |
|
| 978 | - $groupby, |
|
| 979 | - array_filter($orderby), |
|
| 980 | - $limit, |
|
| 981 | - $having, |
|
| 982 | - $serveur, |
|
| 983 | - $requeter |
|
| 984 | - ); |
|
| 985 | - unset($GLOBALS['debug']['aucasou']); |
|
| 986 | - |
|
| 987 | - return $r; |
|
| 716 | + // retirer les criteres vides: |
|
| 717 | + // {X ?} avec X absent de l'URL |
|
| 718 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 719 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 720 | + $menage = false; |
|
| 721 | + foreach ($where as $k => $v) { |
|
| 722 | + if (is_array($v) && count($v)) { |
|
| 723 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 724 | + $op = false; |
|
| 725 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 726 | + $op = false; |
|
| 727 | + } else { |
|
| 728 | + $op = $v[0] ?: $v; |
|
| 729 | + } |
|
| 730 | + } else { |
|
| 731 | + $op = $v; |
|
| 732 | + } |
|
| 733 | + if (!$op || $op == 1 || $op == '0=0') { |
|
| 734 | + unset($where[$k]); |
|
| 735 | + $menage = true; |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 740 | + $groupby = array_diff($groupby, ['']); |
|
| 741 | + |
|
| 742 | + // remplacer les sous requetes recursives au calcul |
|
| 743 | + [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 744 | + foreach ($where_sous as $k => $w) { |
|
| 745 | + $menage = true; |
|
| 746 | + // on recupere la sous requete |
|
| 747 | + $sous = match_self($w); |
|
| 748 | + if ($sous[0] == 'SELF') { |
|
| 749 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 750 | + array_push($where_simples, $sous[2]); |
|
| 751 | + $wheresub = [ |
|
| 752 | + $sous[2], |
|
| 753 | + '0=0' |
|
| 754 | + ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 755 | + $jsub = $join; |
|
| 756 | + // trouver les jointures utiles a |
|
| 757 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 758 | + // ie L1.objet='article' |
|
| 759 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 760 | + $i = 0; |
|
| 761 | + do { |
|
| 762 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 763 | + [$sous[1] . ' AS id'], |
|
| 764 | + $from, |
|
| 765 | + $from_type, |
|
| 766 | + $wheresub, |
|
| 767 | + $jsub, |
|
| 768 | + [], |
|
| 769 | + [], |
|
| 770 | + '', |
|
| 771 | + $having, |
|
| 772 | + $table, |
|
| 773 | + $id, |
|
| 774 | + $serveur, |
|
| 775 | + false |
|
| 776 | + ) . ')'); |
|
| 777 | + if (!$i) { |
|
| 778 | + $i = 1; |
|
| 779 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 780 | + foreach ($join as $cle => $wj) { |
|
| 781 | + if ( |
|
| 782 | + (is_countable($wj) ? count($wj) : 0) == 4 && str_contains($wherestring, (string) "{$cle}.") |
|
| 783 | + ) { |
|
| 784 | + $i = 0; |
|
| 785 | + $wheresub[] = $wj[3]; |
|
| 786 | + unset($jsub[$cle][3]); |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + } while ($i++ < 1); |
|
| 791 | + } |
|
| 792 | + if ($sous[0] == 'SUBSELECT') { |
|
| 793 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 794 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 795 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 796 | + $sous[1], # select |
|
| 797 | + $sous[2], #from |
|
| 798 | + [], #from_type |
|
| 799 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 800 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 801 | + [], #join |
|
| 802 | + $sous[4] ?: [], #groupby |
|
| 803 | + $sous[5] ?: [], #orderby |
|
| 804 | + $sous[6], #limit |
|
| 805 | + $sous[7] ?: [], #having |
|
| 806 | + $table, |
|
| 807 | + $id, |
|
| 808 | + $serveur, |
|
| 809 | + false |
|
| 810 | + ) . ')'); |
|
| 811 | + } |
|
| 812 | + array_pop($where_simples); |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + foreach ($having as $k => $v) { |
|
| 816 | + if (!$v || $v == 1 || $v == '0=0') { |
|
| 817 | + unset($having[$k]); |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + // Installer les jointures. |
|
| 822 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 823 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 824 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 825 | + |
|
| 826 | + $afrom = []; |
|
| 827 | + $equiv = []; |
|
| 828 | + $k = count($join); |
|
| 829 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 830 | + $cle = $cledef; |
|
| 831 | + // le format de join est : |
|
| 832 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 833 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 834 | + if (count($join[$cle]) == 2) { |
|
| 835 | + $join[$cle][] = $join[$cle][1]; |
|
| 836 | + } |
|
| 837 | + if ((is_countable($join[$cle]) ? count($join[$cle]) : 0) == 3) { |
|
| 838 | + $join[$cle][] = ''; |
|
| 839 | + } |
|
| 840 | + [$t, $c, $carr, $and] = $join[$cle]; |
|
| 841 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 842 | + // pour compat avec ancienne convention |
|
| 843 | + if (is_numeric($cle)) { |
|
| 844 | + $cle = "L$k"; |
|
| 845 | + } |
|
| 846 | + $cle_where_lie = "JOIN-$cle"; |
|
| 847 | + if ( |
|
| 848 | + !$menage |
|
| 849 | + || isset($afrom[$cle]) |
|
| 850 | + || calculer_jointnul($cle, $select) |
|
| 851 | + || calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 852 | + || calculer_jointnul($cle, $having) |
|
| 853 | + || calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 854 | + ) { |
|
| 855 | + // corriger les references non explicites dans select |
|
| 856 | + // ou groupby |
|
| 857 | + foreach ($select as $i => $s) { |
|
| 858 | + if ($s == $c) { |
|
| 859 | + $select[$i] = "$cle.$c AS $c"; |
|
| 860 | + break; |
|
| 861 | + } |
|
| 862 | + } |
|
| 863 | + foreach ($groupby as $i => $g) { |
|
| 864 | + if ($g == $c) { |
|
| 865 | + $groupby[$i] = "$cle.$c"; |
|
| 866 | + break; |
|
| 867 | + } |
|
| 868 | + } |
|
| 869 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 870 | + // sans recours a preg_match |
|
| 871 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 872 | + $afrom[$t][$cle] = [ |
|
| 873 | + "\n" . |
|
| 874 | + ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 875 | + $from[$cle], |
|
| 876 | + "AS $cle", |
|
| 877 | + 'ON (', |
|
| 878 | + "$cle.$c", |
|
| 879 | + '=', |
|
| 880 | + "$t.$carr", |
|
| 881 | + ($and ? 'AND ' . $and : '') . |
|
| 882 | + ')' |
|
| 883 | + ]; |
|
| 884 | + if (isset($afrom[$cle])) { |
|
| 885 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 886 | + unset($afrom[$cle]); |
|
| 887 | + } |
|
| 888 | + $equiv[] = $carr; |
|
| 889 | + } else { |
|
| 890 | + unset($join[$cledef]); |
|
| 891 | + if (isset($where_simples[$cle_where_lie])) { |
|
| 892 | + unset($where_simples[$cle_where_lie]); |
|
| 893 | + unset($where[$cle_where_lie]); |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + unset($from[$cle]); |
|
| 897 | + $k--; |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + if (count($afrom)) { |
|
| 901 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 902 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 903 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 904 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 905 | + // ou dans |
|
| 906 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 907 | + // qui comporte plusieurs jointures |
|
| 908 | + // ou dans |
|
| 909 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 910 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 911 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 912 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 913 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 914 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 915 | + |
|
| 916 | + $t = key($from); |
|
| 917 | + $c = current($from); |
|
| 918 | + reset($from); |
|
| 919 | + $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 920 | + if ( |
|
| 921 | + !( |
|
| 922 | + strpos($t, ' ') |
|
| 923 | + // jointure des le depart cf boucle_doc |
|
| 924 | + || calculer_jointnul($t, $select, $e) |
|
| 925 | + || calculer_jointnul($t, $join, $e) |
|
| 926 | + || calculer_jointnul($t, $where, $e) |
|
| 927 | + || calculer_jointnul($t, $orderby, $e) |
|
| 928 | + || calculer_jointnul($t, $groupby, $e) || calculer_jointnul($t, $having, $e) |
|
| 929 | + ) |
|
| 930 | + && count($afrom[$t]) |
|
| 931 | + ) { |
|
| 932 | + $nfrom = reset($afrom[$t]); |
|
| 933 | + $nt = array_key_first($afrom[$t]); |
|
| 934 | + unset($from[$t]); |
|
| 935 | + $from[$nt] = $nfrom[1]; |
|
| 936 | + unset($afrom[$t][$nt]); |
|
| 937 | + $afrom[$nt] = $afrom[$t]; |
|
| 938 | + unset($afrom[$t]); |
|
| 939 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 940 | + $t = $nfrom[4]; |
|
| 941 | + $alias = ''; |
|
| 942 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 943 | + $oldcle = explode('.', $nfrom[6]); |
|
| 944 | + $oldcle = end($oldcle); |
|
| 945 | + $newcle = explode('.', $nfrom[4]); |
|
| 946 | + $newcle = end($newcle); |
|
| 947 | + if ($newcle != $oldcle) { |
|
| 948 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 949 | + // reprendre simplement ce AS |
|
| 950 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 951 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 952 | + $alias = ''; |
|
| 953 | + } else { |
|
| 954 | + $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 958 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 959 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 960 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 961 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 962 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 963 | + } |
|
| 964 | + $from = reinjecte_joint($afrom, $from); |
|
| 965 | + } |
|
| 966 | + if (empty($GLOBALS['debug']) || !is_array($GLOBALS['debug'])) { |
|
| 967 | + $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 968 | + $GLOBALS['debug'] = []; |
|
| 969 | + if ($wasdebug) { |
|
| 970 | + $GLOBALS['debug']['debug'] = true; |
|
| 971 | + } |
|
| 972 | + } |
|
| 973 | + $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 974 | + $r = sql_select( |
|
| 975 | + $select, |
|
| 976 | + $from, |
|
| 977 | + $where, |
|
| 978 | + $groupby, |
|
| 979 | + array_filter($orderby), |
|
| 980 | + $limit, |
|
| 981 | + $having, |
|
| 982 | + $serveur, |
|
| 983 | + $requeter |
|
| 984 | + ); |
|
| 985 | + unset($GLOBALS['debug']['aucasou']); |
|
| 986 | + |
|
| 987 | + return $r; |
|
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | /** |
@@ -995,79 +995,79 @@ discard block |
||
| 995 | 995 | * @return string |
| 996 | 996 | */ |
| 997 | 997 | function calculer_where_to_string($v, $join = 'AND') { |
| 998 | - if (empty($v)) { |
|
| 999 | - return ''; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - if (!is_array($v)) { |
|
| 1003 | - return $v; |
|
| 1004 | - } else { |
|
| 1005 | - $exp = ''; |
|
| 1006 | - if (strtoupper($join) === 'AND') { |
|
| 1007 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1008 | - } else { |
|
| 1009 | - return $exp . join($join, $v); |
|
| 1010 | - } |
|
| 1011 | - } |
|
| 998 | + if (empty($v)) { |
|
| 999 | + return ''; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + if (!is_array($v)) { |
|
| 1003 | + return $v; |
|
| 1004 | + } else { |
|
| 1005 | + $exp = ''; |
|
| 1006 | + if (strtoupper($join) === 'AND') { |
|
| 1007 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1008 | + } else { |
|
| 1009 | + return $exp . join($join, $v); |
|
| 1010 | + } |
|
| 1011 | + } |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | |
| 1015 | 1015 | //condition suffisante (mais non necessaire) pour qu'une table soit utile |
| 1016 | 1016 | |
| 1017 | 1017 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 1018 | - if (!is_array($exp)) { |
|
| 1019 | - if ($equiv) { |
|
| 1020 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1024 | - } else { |
|
| 1025 | - foreach ($exp as $v) { |
|
| 1026 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1027 | - return true; |
|
| 1028 | - } |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - return false; |
|
| 1032 | - } |
|
| 1018 | + if (!is_array($exp)) { |
|
| 1019 | + if ($equiv) { |
|
| 1020 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1024 | + } else { |
|
| 1025 | + foreach ($exp as $v) { |
|
| 1026 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1027 | + return true; |
|
| 1028 | + } |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + return false; |
|
| 1032 | + } |
|
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | 1035 | function reinjecte_joint($afrom, $from) { |
| 1036 | - $from_synth = []; |
|
| 1037 | - foreach ($from as $k => $v) { |
|
| 1038 | - $from_synth[$k] = $from[$k]; |
|
| 1039 | - if (isset($afrom[$k])) { |
|
| 1040 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1041 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1042 | - } |
|
| 1043 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1044 | - unset($afrom[$k]); |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1047 | - |
|
| 1048 | - return $from_synth; |
|
| 1036 | + $from_synth = []; |
|
| 1037 | + foreach ($from as $k => $v) { |
|
| 1038 | + $from_synth[$k] = $from[$k]; |
|
| 1039 | + if (isset($afrom[$k])) { |
|
| 1040 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1041 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1042 | + } |
|
| 1043 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1044 | + unset($afrom[$k]); |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | + |
|
| 1048 | + return $from_synth; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1052 | - if (!is_array($exp)) { |
|
| 1053 | - return preg_replace($equiv, $cle, $exp); |
|
| 1054 | - } else { |
|
| 1055 | - foreach ($exp as $k => $v) { |
|
| 1056 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - return $exp; |
|
| 1060 | - } |
|
| 1052 | + if (!is_array($exp)) { |
|
| 1053 | + return preg_replace($equiv, $cle, $exp); |
|
| 1054 | + } else { |
|
| 1055 | + foreach ($exp as $k => $v) { |
|
| 1056 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + return $exp; |
|
| 1060 | + } |
|
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | 1063 | // calcul du nom du squelette |
| 1064 | 1064 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', string $connect = '') { |
| 1065 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1066 | - if (($l = strlen(_DIR_RACINE)) && strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1067 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - return $mime_type |
|
| 1071 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1072 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1065 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1066 | + if (($l = strlen(_DIR_RACINE)) && strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1067 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + return $mime_type |
|
| 1071 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1072 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1073 | 1073 | } |
@@ -18,15 +18,13 @@ discard block |
||
| 18 | 18 | if ($trace === '?' || defined('_DEBUG_TRACE_QUERIES')) { |
| 19 | 19 | if (defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) { |
| 20 | 20 | $trace = true; |
| 21 | - } |
|
| 22 | - else { |
|
| 21 | + } else { |
|
| 23 | 22 | if (empty($GLOBALS['visiteur_session'])) { |
| 24 | 23 | // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
| 25 | 24 | // car ici on ne sait pas si c'est un hit anonyme |
| 26 | 25 | // ou une requete SQL faite avant chargement de la session |
| 27 | 26 | $trace = (empty($_GET['var_profile']) ? false : '?'); |
| 28 | - } |
|
| 29 | - else { |
|
| 27 | + } else { |
|
| 30 | 28 | include_spip('inc/autoriser'); |
| 31 | 29 | // gare au bouclage sur calcul de droits au premier appel |
| 32 | 30 | // A fortiori quand on demande une trace |
@@ -47,8 +45,7 @@ discard block |
||
| 47 | 45 | // car ici on ne sait pas si c'est un hit anonyme |
| 48 | 46 | // ou une requete SQL faite avant chargement de la session |
| 49 | 47 | $trace = (empty($_GET['var_profile']) ? false : '?'); |
| 50 | - } |
|
| 51 | - else { |
|
| 48 | + } else { |
|
| 52 | 49 | include_spip('inc/autoriser'); |
| 53 | 50 | // gare au bouclage sur calcul de droits au premier appel |
| 54 | 51 | // A fortiori quand on demande une trace |
@@ -10,187 +10,187 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function trace_query_start() { |
| 17 | - static $trace = '?'; |
|
| 18 | - if ($trace === '?' || defined('_DEBUG_TRACE_QUERIES')) { |
|
| 19 | - if (defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) { |
|
| 20 | - $trace = true; |
|
| 21 | - } |
|
| 22 | - else { |
|
| 23 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 24 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 25 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 26 | - // ou une requete SQL faite avant chargement de la session |
|
| 27 | - $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 28 | - } |
|
| 29 | - else { |
|
| 30 | - include_spip('inc/autoriser'); |
|
| 31 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 32 | - // A fortiori quand on demande une trace |
|
| 33 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 34 | - $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - return $trace ? microtime() : 0; |
|
| 17 | + static $trace = '?'; |
|
| 18 | + if ($trace === '?' || defined('_DEBUG_TRACE_QUERIES')) { |
|
| 19 | + if (defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) { |
|
| 20 | + $trace = true; |
|
| 21 | + } |
|
| 22 | + else { |
|
| 23 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 24 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 25 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 26 | + // ou une requete SQL faite avant chargement de la session |
|
| 27 | + $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 28 | + } |
|
| 29 | + else { |
|
| 30 | + include_spip('inc/autoriser'); |
|
| 31 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 32 | + // A fortiori quand on demande une trace |
|
| 33 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 34 | + $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + return $trace ? microtime() : 0; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | function trace_query_end($query, $start, $result, $erreur, $serveur = '') { |
| 43 | - static $trace = '?'; |
|
| 44 | - if ($trace === '?') { |
|
| 45 | - if (empty($GLOBALS['visiteur_session'])) { |
|
| 46 | - // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 47 | - // car ici on ne sait pas si c'est un hit anonyme |
|
| 48 | - // ou une requete SQL faite avant chargement de la session |
|
| 49 | - $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 50 | - } |
|
| 51 | - else { |
|
| 52 | - include_spip('inc/autoriser'); |
|
| 53 | - // gare au bouclage sur calcul de droits au premier appel |
|
| 54 | - // A fortiori quand on demande une trace |
|
| 55 | - $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 56 | - $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - if ($start) { |
|
| 60 | - $end = microtime(); |
|
| 61 | - [$usec, $sec] = explode(' ', (string) $start); |
|
| 62 | - [$usec2, $sec2] = explode(' ', $end); |
|
| 63 | - $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 64 | - pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 65 | - if ($trace) { |
|
| 66 | - trace_query_chrono($dt, $query, $result, $serveur); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 70 | - if ($trace && $erreur && !preg_match('/^select\b/i', (string) $query)) { |
|
| 71 | - erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return $result; |
|
| 43 | + static $trace = '?'; |
|
| 44 | + if ($trace === '?') { |
|
| 45 | + if (empty($GLOBALS['visiteur_session'])) { |
|
| 46 | + // si un anonyme fait un var_profile on est oblige de remplir le tableau des temps en attendant de savoir |
|
| 47 | + // car ici on ne sait pas si c'est un hit anonyme |
|
| 48 | + // ou une requete SQL faite avant chargement de la session |
|
| 49 | + $trace = (empty($_GET['var_profile']) ? false : '?'); |
|
| 50 | + } |
|
| 51 | + else { |
|
| 52 | + include_spip('inc/autoriser'); |
|
| 53 | + // gare au bouclage sur calcul de droits au premier appel |
|
| 54 | + // A fortiori quand on demande une trace |
|
| 55 | + $trace = false; // on ne trace pas la requete provoquee par autoriser('debug') |
|
| 56 | + $trace = (!empty($_GET['var_profile']) && autoriser('debug')); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + if ($start) { |
|
| 60 | + $end = microtime(); |
|
| 61 | + [$usec, $sec] = explode(' ', (string) $start); |
|
| 62 | + [$usec2, $sec2] = explode(' ', $end); |
|
| 63 | + $dt = $sec2 + $usec2 - $sec - $usec; |
|
| 64 | + pipeline('trig_trace_query', ['query' => $query, 'start' => $start, 'end' => $end, 'time' => $dt, 'result' => $result, 'erreur' => $erreur, 'serveur' => $serveur]); |
|
| 65 | + if ($trace) { |
|
| 66 | + trace_query_chrono($dt, $query, $result, $serveur); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + // tracer les erreurs, sauf pour select, c'est fait dans abstract_sql |
|
| 70 | + if ($trace && $erreur && !preg_match('/^select\b/i', (string) $query)) { |
|
| 71 | + erreur_squelette([sql_errno($serveur), $erreur, $query]); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return $result; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function trace_query_chrono($dt, $query, $result, $serveur = '') { |
| 78 | - include_spip('inc/filtres_mini'); |
|
| 79 | - static $tt = 0, $nb = 0; |
|
| 80 | - |
|
| 81 | - $x = _request('var_mode_objet'); |
|
| 82 | - if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 83 | - [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 84 | - if ($x && !preg_match("/$boucle\$/", (string) $x)) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - if ($serveur) { |
|
| 88 | - $boucle .= " ($serveur)"; |
|
| 89 | - } |
|
| 90 | - $boucle = "<b>$boucle</b>"; |
|
| 91 | - } else { |
|
| 92 | - if ($x) { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - $boucle = $contexte = ''; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $tt += $dt; |
|
| 99 | - $nb++; |
|
| 100 | - |
|
| 101 | - $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 102 | - $e = sql_explain($query, $serveur); |
|
| 103 | - $r = str_replace('Resource id ', '', (is_object($result) ? $result::class : $result)); |
|
| 104 | - $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 78 | + include_spip('inc/filtres_mini'); |
|
| 79 | + static $tt = 0, $nb = 0; |
|
| 80 | + |
|
| 81 | + $x = _request('var_mode_objet'); |
|
| 82 | + if (isset($GLOBALS['debug']['aucasou'])) { |
|
| 83 | + [, $boucle, $serveur, $contexte] = $GLOBALS['debug']['aucasou']; |
|
| 84 | + if ($x && !preg_match("/$boucle\$/", (string) $x)) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + if ($serveur) { |
|
| 88 | + $boucle .= " ($serveur)"; |
|
| 89 | + } |
|
| 90 | + $boucle = "<b>$boucle</b>"; |
|
| 91 | + } else { |
|
| 92 | + if ($x) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + $boucle = $contexte = ''; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $tt += $dt; |
|
| 99 | + $nb++; |
|
| 100 | + |
|
| 101 | + $q = preg_replace('/([a-z)`])\s+([A-Z])/', "$1\n<br />$2", spip_htmlentities($query)); |
|
| 102 | + $e = sql_explain($query, $serveur); |
|
| 103 | + $r = str_replace('Resource id ', '', (is_object($result) ? $result::class : $result)); |
|
| 104 | + $GLOBALS['tableau_des_temps'][] = [$dt, $nb, $boucle, $q, $e, $r, $contexte]; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | function chrono_requete($temps) { |
| 109 | - $total = 0; |
|
| 110 | - $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 111 | - $t = $q = $n = $d = []; |
|
| 112 | - // Totaliser les temps et completer le Explain |
|
| 113 | - foreach ($temps as $key => $v) { |
|
| 114 | - [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 115 | - if (is_array($contexte)) { |
|
| 116 | - $k = ($contexte[0] . " $boucle"); |
|
| 117 | - include_spip('public/compiler'); |
|
| 118 | - $env = reconstruire_contexte_compil($contexte); |
|
| 119 | - } else { |
|
| 120 | - $k = $env = $boucle; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $total += $dt; |
|
| 124 | - $t[$key] = $dt; |
|
| 125 | - $q[$key] = $nb; |
|
| 126 | - if (!isset($d[$k])) { |
|
| 127 | - $d[$k] = 0; |
|
| 128 | - $n[$k] = 0; |
|
| 129 | - } |
|
| 130 | - $d[$k] += $dt; |
|
| 131 | - ++$n[$k]; |
|
| 132 | - |
|
| 133 | - if (!is_array($explain)) { |
|
| 134 | - $explain = []; |
|
| 135 | - } |
|
| 136 | - foreach ($explain as $j => $v) { |
|
| 137 | - $explain[$j] = "<tr><th>$j</th><td>" |
|
| 138 | - . str_replace(';', '<br />', (string) $v) |
|
| 139 | - . '</td></tr>'; |
|
| 140 | - } |
|
| 141 | - $e = "<table class='explain'>" |
|
| 142 | - . '<caption>' |
|
| 143 | - . $query |
|
| 144 | - . '</caption>' |
|
| 145 | - . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 146 | - . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 147 | - . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 148 | - . implode('', $explain) |
|
| 149 | - . '</table>'; |
|
| 150 | - |
|
| 151 | - $temps[$key] = [$e, $env, $k]; |
|
| 152 | - } |
|
| 153 | - // Trier par temps d'execution decroissant |
|
| 154 | - array_multisort($t, SORT_DESC, $q, $temps); |
|
| 155 | - arsort($d); |
|
| 156 | - $i = 1; |
|
| 157 | - $t = []; |
|
| 158 | - // Fabriquer les liens de navigations dans le tableau des temps |
|
| 159 | - foreach ($temps as $k => $v) { |
|
| 160 | - $titre = strip_tags((string) $v[2]); |
|
| 161 | - $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 162 | - $href = str_replace("\\'", ''', $href); |
|
| 163 | - |
|
| 164 | - if (!isset($t[$v[2]])) { |
|
| 165 | - $t[$v[2]] = []; |
|
| 166 | - } |
|
| 167 | - $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 168 | - . "<a title='$titre' href='$href'>$i</a>" |
|
| 169 | - . '</span>' |
|
| 170 | - . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 171 | - $i++; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - if ($d['']) { |
|
| 175 | - $d[$hors] = $d['']; |
|
| 176 | - $n[$hors] = $n['']; |
|
| 177 | - $t[$hors] = $t['']; |
|
| 178 | - } |
|
| 179 | - unset($d['']); |
|
| 180 | - // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 181 | - foreach ($d as $k => $v) { |
|
| 182 | - $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 183 | - . implode('', $t[$k]); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $navigation = [ |
|
| 187 | - _T('zbug_statistiques'), |
|
| 188 | - '<tr><td>' |
|
| 189 | - . implode("</td></tr>\n<tr><td>", $d) |
|
| 190 | - . "</td></tr>\n" |
|
| 191 | - . (# _request('var_mode_objet') ? '' : |
|
| 192 | - ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 193 | - ]; |
|
| 194 | - |
|
| 195 | - return [$temps, $navigation]; |
|
| 109 | + $total = 0; |
|
| 110 | + $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 111 | + $t = $q = $n = $d = []; |
|
| 112 | + // Totaliser les temps et completer le Explain |
|
| 113 | + foreach ($temps as $key => $v) { |
|
| 114 | + [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
|
| 115 | + if (is_array($contexte)) { |
|
| 116 | + $k = ($contexte[0] . " $boucle"); |
|
| 117 | + include_spip('public/compiler'); |
|
| 118 | + $env = reconstruire_contexte_compil($contexte); |
|
| 119 | + } else { |
|
| 120 | + $k = $env = $boucle; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $total += $dt; |
|
| 124 | + $t[$key] = $dt; |
|
| 125 | + $q[$key] = $nb; |
|
| 126 | + if (!isset($d[$k])) { |
|
| 127 | + $d[$k] = 0; |
|
| 128 | + $n[$k] = 0; |
|
| 129 | + } |
|
| 130 | + $d[$k] += $dt; |
|
| 131 | + ++$n[$k]; |
|
| 132 | + |
|
| 133 | + if (!is_array($explain)) { |
|
| 134 | + $explain = []; |
|
| 135 | + } |
|
| 136 | + foreach ($explain as $j => $v) { |
|
| 137 | + $explain[$j] = "<tr><th>$j</th><td>" |
|
| 138 | + . str_replace(';', '<br />', (string) $v) |
|
| 139 | + . '</td></tr>'; |
|
| 140 | + } |
|
| 141 | + $e = "<table class='explain'>" |
|
| 142 | + . '<caption>' |
|
| 143 | + . $query |
|
| 144 | + . '</caption>' |
|
| 145 | + . "<tr><th>Time</th><td>$dt</td></tr>" |
|
| 146 | + . "<tr><th>Order</th><td>$nb</td></tr>" |
|
| 147 | + . "<tr><th>Res</th><td>$res</td></tr>" |
|
| 148 | + . implode('', $explain) |
|
| 149 | + . '</table>'; |
|
| 150 | + |
|
| 151 | + $temps[$key] = [$e, $env, $k]; |
|
| 152 | + } |
|
| 153 | + // Trier par temps d'execution decroissant |
|
| 154 | + array_multisort($t, SORT_DESC, $q, $temps); |
|
| 155 | + arsort($d); |
|
| 156 | + $i = 1; |
|
| 157 | + $t = []; |
|
| 158 | + // Fabriquer les liens de navigations dans le tableau des temps |
|
| 159 | + foreach ($temps as $k => $v) { |
|
| 160 | + $titre = strip_tags((string) $v[2]); |
|
| 161 | + $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 162 | + $href = str_replace("\\'", ''', $href); |
|
| 163 | + |
|
| 164 | + if (!isset($t[$v[2]])) { |
|
| 165 | + $t[$v[2]] = []; |
|
| 166 | + } |
|
| 167 | + $t[$v[2]][] = "<span class='spip-debug-arg'> " |
|
| 168 | + . "<a title='$titre' href='$href'>$i</a>" |
|
| 169 | + . '</span>' |
|
| 170 | + . ((count($t[$v[2]]) % 10 == 9) ? '<br />' : ''); |
|
| 171 | + $i++; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + if ($d['']) { |
|
| 175 | + $d[$hors] = $d['']; |
|
| 176 | + $n[$hors] = $n['']; |
|
| 177 | + $t[$hors] = $t['']; |
|
| 178 | + } |
|
| 179 | + unset($d['']); |
|
| 180 | + // Fabriquer le tableau des liens de navigation dans le grand tableau |
|
| 181 | + foreach ($d as $k => $v) { |
|
| 182 | + $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 183 | + . implode('', $t[$k]); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $navigation = [ |
|
| 187 | + _T('zbug_statistiques'), |
|
| 188 | + '<tr><td>' |
|
| 189 | + . implode("</td></tr>\n<tr><td>", $d) |
|
| 190 | + . "</td></tr>\n" |
|
| 191 | + . (# _request('var_mode_objet') ? '' : |
|
| 192 | + ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 193 | + ]; |
|
| 194 | + |
|
| 195 | + return [$temps, $navigation]; |
|
| 196 | 196 | } |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | function chrono_requete($temps) { |
| 109 | 109 | $total = 0; |
| 110 | - $hors = '<i>' . _T('zbug_hors_compilation') . '</i>'; |
|
| 110 | + $hors = '<i>'._T('zbug_hors_compilation').'</i>'; |
|
| 111 | 111 | $t = $q = $n = $d = []; |
| 112 | 112 | // Totaliser les temps et completer le Explain |
| 113 | 113 | foreach ($temps as $key => $v) { |
| 114 | 114 | [$dt, $nb, $boucle, $query, $explain, $res, $contexte] = $v; |
| 115 | 115 | if (is_array($contexte)) { |
| 116 | - $k = ($contexte[0] . " $boucle"); |
|
| 116 | + $k = ($contexte[0]." $boucle"); |
|
| 117 | 117 | include_spip('public/compiler'); |
| 118 | 118 | $env = reconstruire_contexte_compil($contexte); |
| 119 | 119 | } else { |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | // Fabriquer les liens de navigations dans le tableau des temps |
| 159 | 159 | foreach ($temps as $k => $v) { |
| 160 | 160 | $titre = strip_tags((string) $v[2]); |
| 161 | - $href = quote_amp($GLOBALS['REQUEST_URI']) . "#req$i"; |
|
| 161 | + $href = quote_amp($GLOBALS['REQUEST_URI'])."#req$i"; |
|
| 162 | 162 | $href = str_replace("\\'", ''', $href); |
| 163 | 163 | |
| 164 | 164 | if (!isset($t[$v[2]])) { |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | unset($d['']); |
| 180 | 180 | // Fabriquer le tableau des liens de navigation dans le grand tableau |
| 181 | 181 | foreach ($d as $k => $v) { |
| 182 | - $d[$k] = $n[$k] . "</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 182 | + $d[$k] = $n[$k]."</td><td>$k</td><td class='time'>$v</td><td class='liste-reqs'>" |
|
| 183 | 183 | . implode('', $t[$k]); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | . implode("</td></tr>\n<tr><td>", $d) |
| 190 | 190 | . "</td></tr>\n" |
| 191 | 191 | . (# _request('var_mode_objet') ? '' : |
| 192 | - ('<tr><td>' . (is_countable($temps) ? count($temps) : 0) . '</td><td>' . _T('info_total') . '</td><td class="time">' . $total . '</td><td></td></tr>')) |
|
| 192 | + ('<tr><td>'.(is_countable($temps) ? count($temps) : 0).'</td><td>'._T('info_total').'</td><td class="time">'.$total.'</td><td></td></tr>')) |
|
| 193 | 193 | ]; |
| 194 | 194 | |
| 195 | 195 | return [$temps, $navigation]; |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | $t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']); |
| 76 | 76 | if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) { |
| 77 | 77 | $t *= 0.9; // marge de securite |
| 78 | - echo round($t / 1_000_000, 3) . ' Mpx'; |
|
| 78 | + echo round($t / 1_000_000, 3).' Mpx'; |
|
| 79 | 79 | } else { |
| 80 | 80 | // c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue" |
| 81 | 81 | $t = 0; |
@@ -111,19 +111,19 @@ discard block |
||
| 111 | 111 | $image_source = chemin_image('test.png'); |
| 112 | 112 | $GLOBALS['redirect'] = generer_url_action( |
| 113 | 113 | 'tester_taille', |
| 114 | - "i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test'] |
|
| 114 | + "i=$i&arg=".$GLOBALS['taille_min'].'-'.$GLOBALS['taille_test'] |
|
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | 117 | ob_start('action_tester_taille_error_handler'); |
| 118 | 118 | filtrer('image_recadre', $image_source, $taille, $taille); |
| 119 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 119 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-".$GLOBALS['taille_max']); |
|
| 120 | 120 | |
| 121 | 121 | // si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee |
| 122 | 122 | // si $GLOBALS['taille_min']==0 (car on est au premier coup) |
| 123 | 123 | if ($GLOBALS['taille_min'] == 0) { |
| 124 | 124 | $taille = $GLOBALS['taille_max']; |
| 125 | 125 | filtrer('image_recadre', $image_source, $taille, $taille); |
| 126 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 126 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-".$GLOBALS['taille_max']); |
|
| 127 | 127 | } |
| 128 | 128 | ob_end_clean(); |
| 129 | 129 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/headers'); |
| 23 | 23 | |
@@ -34,12 +34,12 @@ discard block |
||
| 34 | 34 | * Sortie du buffer |
| 35 | 35 | **/ |
| 36 | 36 | function action_tester_taille_error_handler($output) { |
| 37 | - // on est ici, donc echec lors de la creation de l'image |
|
| 38 | - if (!empty($GLOBALS['redirect'])) { |
|
| 39 | - return redirige_formulaire($GLOBALS['redirect']); |
|
| 40 | - } |
|
| 37 | + // on est ici, donc echec lors de la creation de l'image |
|
| 38 | + if (!empty($GLOBALS['redirect'])) { |
|
| 39 | + return redirige_formulaire($GLOBALS['redirect']); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - return $output; |
|
| 42 | + return $output; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
@@ -57,77 +57,77 @@ discard block |
||
| 57 | 57 | **/ |
| 58 | 58 | function action_tester_taille_dist() { |
| 59 | 59 | |
| 60 | - if (!autoriser('configurer')) { |
|
| 61 | - return; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - $taille = _request('arg'); |
|
| 65 | - $taille = explode('-', (string) $taille); |
|
| 66 | - |
|
| 67 | - $GLOBALS['taille_max'] = end($taille); |
|
| 68 | - $GLOBALS['taille_min'] = 0; |
|
| 69 | - if (count($taille) > 1) { |
|
| 70 | - $GLOBALS['taille_min'] = reset($taille); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // si l'intervalle est assez petit, on garde la valeur min |
|
| 74 | - if ($GLOBALS['taille_max'] * $GLOBALS['taille_max'] - $GLOBALS['taille_min'] * $GLOBALS['taille_min'] < 50000) { |
|
| 75 | - $t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']); |
|
| 76 | - if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) { |
|
| 77 | - $t *= 0.9; // marge de securite |
|
| 78 | - echo round($t / 1_000_000, 3) . ' Mpx'; |
|
| 79 | - } else { |
|
| 80 | - // c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue" |
|
| 81 | - $t = 0; |
|
| 82 | - echo '∞'; |
|
| 83 | - } |
|
| 84 | - ecrire_meta('max_taille_vignettes', $t, 'non'); |
|
| 85 | - die(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $taille = $GLOBALS['taille_test'] = round(($GLOBALS['taille_max'] + $GLOBALS['taille_min']) / 2); |
|
| 89 | - |
|
| 90 | - include_spip('inc/filtres'); |
|
| 91 | - // des inclusions representatives d'un hit prive et/ou public pour la conso memoire |
|
| 92 | - include_spip('public/assembler'); |
|
| 93 | - include_spip('public/balises'); |
|
| 94 | - include_spip('public/boucles'); |
|
| 95 | - include_spip('public/cacher'); |
|
| 96 | - include_spip('public/compiler'); |
|
| 97 | - include_spip('public/composer'); |
|
| 98 | - include_spip('public/criteres'); |
|
| 99 | - include_spip('public/interfaces'); |
|
| 100 | - include_spip('public/parametrer'); |
|
| 101 | - include_spip('public/phraser_html'); |
|
| 102 | - include_spip('public/references'); |
|
| 103 | - |
|
| 104 | - include_spip('inc/presentation'); |
|
| 105 | - include_spip('inc/charsets'); |
|
| 106 | - include_spip('inc/documents'); |
|
| 107 | - include_spip('inc/header'); |
|
| 108 | - propre('<doc1>'); // charger propre avec le trairement d'un modele |
|
| 109 | - |
|
| 110 | - $i = _request('i') + 1; |
|
| 111 | - $image_source = chemin_image('test.png'); |
|
| 112 | - $GLOBALS['redirect'] = generer_url_action( |
|
| 113 | - 'tester_taille', |
|
| 114 | - "i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test'] |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - ob_start('action_tester_taille_error_handler'); |
|
| 118 | - filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 119 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 120 | - |
|
| 121 | - // si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee |
|
| 122 | - // si $GLOBALS['taille_min']==0 (car on est au premier coup) |
|
| 123 | - if ($GLOBALS['taille_min'] == 0) { |
|
| 124 | - $taille = $GLOBALS['taille_max']; |
|
| 125 | - filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 126 | - $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 127 | - } |
|
| 128 | - ob_end_clean(); |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - // on est ici, donc pas de plantage |
|
| 132 | - echo redirige_formulaire($GLOBALS['redirect']); |
|
| 60 | + if (!autoriser('configurer')) { |
|
| 61 | + return; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + $taille = _request('arg'); |
|
| 65 | + $taille = explode('-', (string) $taille); |
|
| 66 | + |
|
| 67 | + $GLOBALS['taille_max'] = end($taille); |
|
| 68 | + $GLOBALS['taille_min'] = 0; |
|
| 69 | + if (count($taille) > 1) { |
|
| 70 | + $GLOBALS['taille_min'] = reset($taille); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // si l'intervalle est assez petit, on garde la valeur min |
|
| 74 | + if ($GLOBALS['taille_max'] * $GLOBALS['taille_max'] - $GLOBALS['taille_min'] * $GLOBALS['taille_min'] < 50000) { |
|
| 75 | + $t = ($GLOBALS['taille_min'] * $GLOBALS['taille_min']); |
|
| 76 | + if ($GLOBALS['taille_min'] !== $GLOBALS['taille_max']) { |
|
| 77 | + $t *= 0.9; // marge de securite |
|
| 78 | + echo round($t / 1_000_000, 3) . ' Mpx'; |
|
| 79 | + } else { |
|
| 80 | + // c'est un cas "on a reussi la borne max initiale, donc on a pas de limite connue" |
|
| 81 | + $t = 0; |
|
| 82 | + echo '∞'; |
|
| 83 | + } |
|
| 84 | + ecrire_meta('max_taille_vignettes', $t, 'non'); |
|
| 85 | + die(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $taille = $GLOBALS['taille_test'] = round(($GLOBALS['taille_max'] + $GLOBALS['taille_min']) / 2); |
|
| 89 | + |
|
| 90 | + include_spip('inc/filtres'); |
|
| 91 | + // des inclusions representatives d'un hit prive et/ou public pour la conso memoire |
|
| 92 | + include_spip('public/assembler'); |
|
| 93 | + include_spip('public/balises'); |
|
| 94 | + include_spip('public/boucles'); |
|
| 95 | + include_spip('public/cacher'); |
|
| 96 | + include_spip('public/compiler'); |
|
| 97 | + include_spip('public/composer'); |
|
| 98 | + include_spip('public/criteres'); |
|
| 99 | + include_spip('public/interfaces'); |
|
| 100 | + include_spip('public/parametrer'); |
|
| 101 | + include_spip('public/phraser_html'); |
|
| 102 | + include_spip('public/references'); |
|
| 103 | + |
|
| 104 | + include_spip('inc/presentation'); |
|
| 105 | + include_spip('inc/charsets'); |
|
| 106 | + include_spip('inc/documents'); |
|
| 107 | + include_spip('inc/header'); |
|
| 108 | + propre('<doc1>'); // charger propre avec le trairement d'un modele |
|
| 109 | + |
|
| 110 | + $i = _request('i') + 1; |
|
| 111 | + $image_source = chemin_image('test.png'); |
|
| 112 | + $GLOBALS['redirect'] = generer_url_action( |
|
| 113 | + 'tester_taille', |
|
| 114 | + "i=$i&arg=" . $GLOBALS['taille_min'] . '-' . $GLOBALS['taille_test'] |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + ob_start('action_tester_taille_error_handler'); |
|
| 118 | + filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 119 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 120 | + |
|
| 121 | + // si la valeur intermediaire a reussi, on teste la valeur maxi qui est peut etre sous estimee |
|
| 122 | + // si $GLOBALS['taille_min']==0 (car on est au premier coup) |
|
| 123 | + if ($GLOBALS['taille_min'] == 0) { |
|
| 124 | + $taille = $GLOBALS['taille_max']; |
|
| 125 | + filtrer('image_recadre', $image_source, $taille, $taille); |
|
| 126 | + $GLOBALS['redirect'] = generer_url_action('tester_taille', "i=$i&arg=$taille-" . $GLOBALS['taille_max']); |
|
| 127 | + } |
|
| 128 | + ob_end_clean(); |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + // on est ici, donc pas de plantage |
|
| 132 | + echo redirige_formulaire($GLOBALS['redirect']); |
|
| 133 | 133 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); # pour le nom de fichier |
@@ -29,45 +29,45 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function action_supprimer_rubrique_dist($id_rubrique = null) { |
| 31 | 31 | |
| 32 | - if (is_null($id_rubrique)) { |
|
| 33 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 34 | - $id_rubrique = $securiser_action(); |
|
| 35 | - } |
|
| 32 | + if (is_null($id_rubrique)) { |
|
| 33 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 34 | + $id_rubrique = $securiser_action(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - if ((int) $id_rubrique) { |
|
| 38 | - sql_delete('spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 39 | - // Les admin restreints qui n'administraient que cette rubrique |
|
| 40 | - // deviennent redacteurs |
|
| 41 | - // (il y a sans doute moyen de faire ca avec un having) |
|
| 37 | + if ((int) $id_rubrique) { |
|
| 38 | + sql_delete('spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 39 | + // Les admin restreints qui n'administraient que cette rubrique |
|
| 40 | + // deviennent redacteurs |
|
| 41 | + // (il y a sans doute moyen de faire ca avec un having) |
|
| 42 | 42 | |
| 43 | - $q = sql_select('id_auteur', 'spip_auteurs_liens', "objet='rubrique' AND id_objet=" . (int) $id_rubrique); |
|
| 44 | - while ($r = sql_fetch($q)) { |
|
| 45 | - $id_auteur = $r['id_auteur']; |
|
| 46 | - // degrader avant de supprimer la restriction d'admin |
|
| 47 | - // section critique sur les droits |
|
| 48 | - $n = sql_countsel( |
|
| 49 | - 'spip_auteurs_liens', |
|
| 50 | - "objet='rubrique' AND id_objet!=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur |
|
| 51 | - ); |
|
| 52 | - if (!$n) { |
|
| 53 | - include_spip('action/editer_auteur'); |
|
| 54 | - auteur_modifier($id_auteur, ['statut' => '1comite']); |
|
| 55 | - } |
|
| 56 | - sql_delete( |
|
| 57 | - 'spip_auteurs_liens', |
|
| 58 | - "objet='rubrique' AND id_objet=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur |
|
| 59 | - ); |
|
| 60 | - } |
|
| 61 | - // menu_rubriques devra recalculer |
|
| 62 | - effacer_meta('date_calcul_rubriques'); |
|
| 43 | + $q = sql_select('id_auteur', 'spip_auteurs_liens', "objet='rubrique' AND id_objet=" . (int) $id_rubrique); |
|
| 44 | + while ($r = sql_fetch($q)) { |
|
| 45 | + $id_auteur = $r['id_auteur']; |
|
| 46 | + // degrader avant de supprimer la restriction d'admin |
|
| 47 | + // section critique sur les droits |
|
| 48 | + $n = sql_countsel( |
|
| 49 | + 'spip_auteurs_liens', |
|
| 50 | + "objet='rubrique' AND id_objet!=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur |
|
| 51 | + ); |
|
| 52 | + if (!$n) { |
|
| 53 | + include_spip('action/editer_auteur'); |
|
| 54 | + auteur_modifier($id_auteur, ['statut' => '1comite']); |
|
| 55 | + } |
|
| 56 | + sql_delete( |
|
| 57 | + 'spip_auteurs_liens', |
|
| 58 | + "objet='rubrique' AND id_objet=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur |
|
| 59 | + ); |
|
| 60 | + } |
|
| 61 | + // menu_rubriques devra recalculer |
|
| 62 | + effacer_meta('date_calcul_rubriques'); |
|
| 63 | 63 | |
| 64 | - // Une rubrique supprimable n'avait pas le statut "publie" |
|
| 65 | - // donc rien de neuf pour la rubrique parente |
|
| 66 | - include_spip('inc/rubriques'); |
|
| 67 | - calculer_langues_rubriques(); |
|
| 64 | + // Une rubrique supprimable n'avait pas le statut "publie" |
|
| 65 | + // donc rien de neuf pour la rubrique parente |
|
| 66 | + include_spip('inc/rubriques'); |
|
| 67 | + calculer_langues_rubriques(); |
|
| 68 | 68 | |
| 69 | - // invalider les caches marques de cette rubrique |
|
| 70 | - include_spip('inc/invalideur'); |
|
| 71 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 72 | - } |
|
| 69 | + // invalider les caches marques de cette rubrique |
|
| 70 | + include_spip('inc/invalideur'); |
|
| 71 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | return; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | -include_spip('inc/charsets'); # pour le nom de fichier |
|
| 22 | +include_spip('inc/charsets'); # pour le nom de fichier |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * Effacer une rubrique |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | if ((int) $id_rubrique) { |
| 38 | - sql_delete('spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 38 | + sql_delete('spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 39 | 39 | // Les admin restreints qui n'administraient que cette rubrique |
| 40 | 40 | // deviennent redacteurs |
| 41 | 41 | // (il y a sans doute moyen de faire ca avec un having) |
| 42 | 42 | |
| 43 | - $q = sql_select('id_auteur', 'spip_auteurs_liens', "objet='rubrique' AND id_objet=" . (int) $id_rubrique); |
|
| 43 | + $q = sql_select('id_auteur', 'spip_auteurs_liens', "objet='rubrique' AND id_objet=".(int) $id_rubrique); |
|
| 44 | 44 | while ($r = sql_fetch($q)) { |
| 45 | 45 | $id_auteur = $r['id_auteur']; |
| 46 | 46 | // degrader avant de supprimer la restriction d'admin |
| 47 | 47 | // section critique sur les droits |
| 48 | 48 | $n = sql_countsel( |
| 49 | 49 | 'spip_auteurs_liens', |
| 50 | - "objet='rubrique' AND id_objet!=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur |
|
| 50 | + "objet='rubrique' AND id_objet!=".(int) $id_rubrique.' AND id_auteur='.(int) $id_auteur |
|
| 51 | 51 | ); |
| 52 | 52 | if (!$n) { |
| 53 | 53 | include_spip('action/editer_auteur'); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | sql_delete( |
| 57 | 57 | 'spip_auteurs_liens', |
| 58 | - "objet='rubrique' AND id_objet=" . (int) $id_rubrique . ' AND id_auteur=' . (int) $id_auteur |
|
| 58 | + "objet='rubrique' AND id_objet=".(int) $id_rubrique.' AND id_auteur='.(int) $id_auteur |
|
| 59 | 59 | ); |
| 60 | 60 | } |
| 61 | 61 | // menu_rubriques devra recalculer |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | defined('URLS_PAGE_EXEMPLE') || define('URLS_PAGE_EXEMPLE', 'spip.php?article12'); |
@@ -29,23 +29,23 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function urls_page_generer_url_objet_dist(int $id, string $objet, string $args = '', string $ancre = ''): string { |
| 31 | 31 | |
| 32 | - if ($generer_url_externe = charger_fonction_url($objet, 'defaut')) { |
|
| 33 | - $url = $generer_url_externe($id, $args, $ancre); |
|
| 34 | - // une url === null indique "je ne traite pas cette url, appliquez le calcul standard" |
|
| 35 | - // une url vide est une url vide, ne rien faire de plus |
|
| 36 | - if (!is_null($url)) { |
|
| 37 | - return $url; |
|
| 38 | - } |
|
| 39 | - } |
|
| 32 | + if ($generer_url_externe = charger_fonction_url($objet, 'defaut')) { |
|
| 33 | + $url = $generer_url_externe($id, $args, $ancre); |
|
| 34 | + // une url === null indique "je ne traite pas cette url, appliquez le calcul standard" |
|
| 35 | + // une url vide est une url vide, ne rien faire de plus |
|
| 36 | + if (!is_null($url)) { |
|
| 37 | + return $url; |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - $url = \_debut_urls_page . $objet . \_separateur_urls_page |
|
| 42 | - . $id . \_terminaison_urls_page; |
|
| 41 | + $url = \_debut_urls_page . $objet . \_separateur_urls_page |
|
| 42 | + . $id . \_terminaison_urls_page; |
|
| 43 | 43 | |
| 44 | - if ($args) { |
|
| 45 | - $args = strpos($url, '?') ? "&$args" : "?$args"; |
|
| 46 | - } |
|
| 44 | + if ($args) { |
|
| 45 | + $args = strpos($url, '?') ? "&$args" : "?$args"; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : ''); |
|
| 48 | + return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : ''); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -61,27 +61,27 @@ discard block |
||
| 61 | 61 | */ |
| 62 | 62 | function urls_page_decoder_url_dist(string $url, string $entite, array $contexte = []): array { |
| 63 | 63 | |
| 64 | - // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23 |
|
| 65 | - if ($GLOBALS['profondeur_url'] > 0 && $entite == 'sommaire') { |
|
| 66 | - return [[], '404']; |
|
| 67 | - } |
|
| 64 | + // traiter les injections du type domaine.org/spip.php/cestnimportequoi/ou/encore/plus/rubrique23 |
|
| 65 | + if ($GLOBALS['profondeur_url'] > 0 && $entite == 'sommaire') { |
|
| 66 | + return [[], '404']; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - include_spip('inc/urls'); |
|
| 70 | - $r = nettoyer_url_page($url, $contexte); |
|
| 71 | - if ($r) { |
|
| 72 | - array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici |
|
| 73 | - return $r; |
|
| 74 | - } |
|
| 69 | + include_spip('inc/urls'); |
|
| 70 | + $r = nettoyer_url_page($url, $contexte); |
|
| 71 | + if ($r) { |
|
| 72 | + array_pop($r); // nettoyer_url_page renvoie un argument de plus inutile ici |
|
| 73 | + return $r; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /* |
|
| 76 | + /* |
|
| 77 | 77 | * Le bloc qui suit sert a faciliter les transitions depuis |
| 78 | 78 | * le mode 'urls-propres' vers les modes 'urls-standard' et 'url-html' |
| 79 | 79 | * Il est inutile de le recopier si vous personnalisez vos URLs |
| 80 | 80 | * et votre .htaccess |
| 81 | 81 | */ |
| 82 | - // Si on est revenu en mode html, mais c'est une ancienne url_propre |
|
| 83 | - // on ne redirige pas, on assume le nouveau contexte (si possible) |
|
| 84 | - $url_propre = $url ?? $_SERVER['REDIRECT_url_propre'] ?? $_ENV['url_propre'] ?? ''; |
|
| 85 | - return urls_transition_retrouver_anciennes_url_propres($url_propre, $entite, $contexte); |
|
| 86 | - /* Fin du bloc compatibilite url-propres */ |
|
| 82 | + // Si on est revenu en mode html, mais c'est une ancienne url_propre |
|
| 83 | + // on ne redirige pas, on assume le nouveau contexte (si possible) |
|
| 84 | + $url_propre = $url ?? $_SERVER['REDIRECT_url_propre'] ?? $_ENV['url_propre'] ?? ''; |
|
| 85 | + return urls_transition_retrouver_anciennes_url_propres($url_propre, $entite, $contexte); |
|
| 86 | + /* Fin du bloc compatibilite url-propres */ |
|
| 87 | 87 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | # attention toutefois seuls '' et '=' figurent dans les modes de compatibilite |
| 23 | 23 | define('_separateur_urls_page', ''); |
| 24 | 24 | # on peut indiquer '' si on a installe le .htaccess |
| 25 | -define('_debut_urls_page', get_spip_script('./') . '?'); |
|
| 25 | +define('_debut_urls_page', get_spip_script('./').'?'); |
|
| 26 | 26 | ####### |
| 27 | 27 | /** |
| 28 | 28 | * Generer l'url d'un objet SPIP |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - $url = \_debut_urls_page . $objet . \_separateur_urls_page |
|
| 42 | - . $id . \_terminaison_urls_page; |
|
| 41 | + $url = \_debut_urls_page.$objet.\_separateur_urls_page |
|
| 42 | + . $id.\_terminaison_urls_page; |
|
| 43 | 43 | |
| 44 | 44 | if ($args) { |
| 45 | 45 | $args = strpos($url, '?') ? "&$args" : "?$args"; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - return _DIR_RACINE . $url . $args . ($ancre ? "#$ancre" : ''); |
|
| 48 | + return _DIR_RACINE.$url.$args.($ancre ? "#$ancre" : ''); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -126,10 +126,10 @@ |
||
| 126 | 126 | $code = "quete_logo('$id_objet', '$onoff', $_id_objet, $_id_rubrique)"; |
| 127 | 127 | |
| 128 | 128 | if ($champ) { |
| 129 | - return "table_valeur($code, '" . addslashes($champ) . "')"; |
|
| 129 | + return "table_valeur($code, '".addslashes($champ)."')"; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $align = preg_replace(',\W,', '', $align); |
| 133 | 133 | |
| 134 | - return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 134 | + return "quete_html_logo($code, '$align', ".($_lien ?: "''").')'; |
|
| 135 | 135 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -48,38 +48,38 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function balise_ID_LOGO__dist($p) { |
| 50 | 50 | |
| 51 | - preg_match(',^ID_LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 52 | - $type = strtolower($regs[1]); |
|
| 53 | - $suite_logo = $regs[2]; |
|
| 54 | - |
|
| 55 | - // cas de #ID_LOGO_SITE_SPIP |
|
| 56 | - if ($type == 'site_spip') { |
|
| 57 | - $type = 'site'; |
|
| 58 | - $_id_objet = "\"'0'\""; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $id_objet = id_table_objet($type); |
|
| 62 | - if (!isset($_id_objet)) { |
|
| 63 | - $_id_objet = champ_sql($id_objet, $p); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 67 | - if ($type == 'document') { |
|
| 68 | - $qconnect = _q($connect); |
|
| 69 | - $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 70 | - $code = "table_valeur($doc, 'id_vignette')"; |
|
| 71 | - } elseif ($connect) { |
|
| 72 | - $code = "''"; |
|
| 73 | - spip_logger()->info('Les logos distants ne sont pas prevus'); |
|
| 74 | - } else { |
|
| 75 | - $champ_logo = 'id'; |
|
| 76 | - $code = generer_code_logo($id_objet, $_id_objet, $type, '', "''", $p, $suite_logo, $champ_logo); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $p->code = $code; |
|
| 80 | - $p->interdire_scripts = false; |
|
| 81 | - |
|
| 82 | - return $p; |
|
| 51 | + preg_match(',^ID_LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i', $p->nom_champ, $regs); |
|
| 52 | + $type = strtolower($regs[1]); |
|
| 53 | + $suite_logo = $regs[2]; |
|
| 54 | + |
|
| 55 | + // cas de #ID_LOGO_SITE_SPIP |
|
| 56 | + if ($type == 'site_spip') { |
|
| 57 | + $type = 'site'; |
|
| 58 | + $_id_objet = "\"'0'\""; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $id_objet = id_table_objet($type); |
|
| 62 | + if (!isset($_id_objet)) { |
|
| 63 | + $_id_objet = champ_sql($id_objet, $p); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + $connect = $p->id_boucle ? $p->boucles[$p->id_boucle]->sql_serveur : ''; |
|
| 67 | + if ($type == 'document') { |
|
| 68 | + $qconnect = _q($connect); |
|
| 69 | + $doc = "quete_document($_id_objet, $qconnect)"; |
|
| 70 | + $code = "table_valeur($doc, 'id_vignette')"; |
|
| 71 | + } elseif ($connect) { |
|
| 72 | + $code = "''"; |
|
| 73 | + spip_logger()->info('Les logos distants ne sont pas prevus'); |
|
| 74 | + } else { |
|
| 75 | + $champ_logo = 'id'; |
|
| 76 | + $code = generer_code_logo($id_objet, $_id_objet, $type, '', "''", $p, $suite_logo, $champ_logo); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $p->code = $code; |
|
| 80 | + $p->interdire_scripts = false; |
|
| 81 | + |
|
| 82 | + return $p; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -108,28 +108,28 @@ discard block |
||
| 108 | 108 | * Code compilé retournant le chemin du logo ou le code HTML du logo. |
| 109 | 109 | **/ |
| 110 | 110 | function generer_code_logo($id_objet, $_id_objet, $type, $align, $_lien, $p, $suite, string $champ = ''): string { |
| 111 | - $onoff = 'ON'; |
|
| 112 | - $_id_rubrique = "''"; |
|
| 111 | + $onoff = 'ON'; |
|
| 112 | + $_id_rubrique = "''"; |
|
| 113 | 113 | |
| 114 | - if ($type === 'rubrique') { |
|
| 115 | - $_id_rubrique = "quete_parent($_id_objet)"; |
|
| 116 | - } |
|
| 114 | + if ($type === 'rubrique') { |
|
| 115 | + $_id_rubrique = "quete_parent($_id_objet)"; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - if ($suite === '_SURVOL') { |
|
| 119 | - $onoff = 'off'; |
|
| 120 | - } elseif ($suite === '_NORMAL') { |
|
| 121 | - $onoff = 'on'; |
|
| 122 | - } elseif ($suite === '_RUBRIQUE') { |
|
| 123 | - $_id_rubrique = champ_sql('id_rubrique', $p); |
|
| 124 | - } |
|
| 118 | + if ($suite === '_SURVOL') { |
|
| 119 | + $onoff = 'off'; |
|
| 120 | + } elseif ($suite === '_NORMAL') { |
|
| 121 | + $onoff = 'on'; |
|
| 122 | + } elseif ($suite === '_RUBRIQUE') { |
|
| 123 | + $_id_rubrique = champ_sql('id_rubrique', $p); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - $code = "quete_logo('$id_objet', '$onoff', $_id_objet, $_id_rubrique)"; |
|
| 126 | + $code = "quete_logo('$id_objet', '$onoff', $_id_objet, $_id_rubrique)"; |
|
| 127 | 127 | |
| 128 | - if ($champ) { |
|
| 129 | - return "table_valeur($code, '" . addslashes($champ) . "')"; |
|
| 130 | - } |
|
| 128 | + if ($champ) { |
|
| 129 | + return "table_valeur($code, '" . addslashes($champ) . "')"; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - $align = preg_replace(',\W,', '', $align); |
|
| 132 | + $align = preg_replace(',\W,', '', $align); |
|
| 133 | 133 | |
| 134 | - return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 134 | + return "quete_html_logo($code, '$align', " . ($_lien ?: "''") . ')'; |
|
| 135 | 135 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('base/abstract_sql'); |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * Pile complétée du code compilé |
| 44 | 44 | **/ |
| 45 | 45 | function balise_FORMULAIRE_INSCRIPTION($p) { |
| 46 | - return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 46 | + return calculer_balise_dynamique($p, 'FORMULAIRE_INSCRIPTION', []); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -73,19 +73,19 @@ discard block |
||
| 73 | 73 | * - chaîne vide sinon. |
| 74 | 74 | */ |
| 75 | 75 | function balise_FORMULAIRE_INSCRIPTION_stat($args, $context_compil) { |
| 76 | - [$mode, $id_ou_options, $retour] = array_pad($args, 3, null); |
|
| 76 | + [$mode, $id_ou_options, $retour] = array_pad($args, 3, null); |
|
| 77 | 77 | |
| 78 | - // Compatibilité avec l'ancien param "id" dans les deux sens |
|
| 79 | - if (!is_array($id_ou_options)) { |
|
| 80 | - $options = ['id' => (int) $id_ou_options]; |
|
| 81 | - $id = $options['id']; |
|
| 82 | - }else { |
|
| 83 | - $options = $id_ou_options; |
|
| 84 | - $id = (int) ($id_ou_options['id'] ?? 0); |
|
| 85 | - } |
|
| 78 | + // Compatibilité avec l'ancien param "id" dans les deux sens |
|
| 79 | + if (!is_array($id_ou_options)) { |
|
| 80 | + $options = ['id' => (int) $id_ou_options]; |
|
| 81 | + $id = $options['id']; |
|
| 82 | + }else { |
|
| 83 | + $options = $id_ou_options; |
|
| 84 | + $id = (int) ($id_ou_options['id'] ?? 0); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - include_spip('action/inscrire_auteur'); |
|
| 88 | - $mode = tester_statut_inscription($mode, $id); |
|
| 87 | + include_spip('action/inscrire_auteur'); |
|
| 88 | + $mode = tester_statut_inscription($mode, $id); |
|
| 89 | 89 | |
| 90 | - return $mode ? [$mode, $options, $retour] : ''; |
|
| 90 | + return $mode ? [$mode, $options, $retour] : ''; |
|
| 91 | 91 | } |
@@ -79,7 +79,7 @@ |
||
| 79 | 79 | if (!is_array($id_ou_options)) { |
| 80 | 80 | $options = ['id' => (int) $id_ou_options]; |
| 81 | 81 | $id = $options['id']; |
| 82 | - }else { |
|
| 82 | + } else { |
|
| 83 | 83 | $options = $id_ou_options; |
| 84 | 84 | $id = (int) ($id_ou_options['id'] ?? 0); |
| 85 | 85 | } |
@@ -79,7 +79,7 @@ |
||
| 79 | 79 | if (!is_array($id_ou_options)) { |
| 80 | 80 | $options = ['id' => (int) $id_ou_options]; |
| 81 | 81 | $id = $options['id']; |
| 82 | - }else { |
|
| 82 | + } else { |
|
| 83 | 83 | $options = $id_ou_options; |
| 84 | 84 | $id = (int) ($id_ou_options['id'] ?? 0); |
| 85 | 85 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $type = reset($objets); |
| 160 | 160 | $type = objet_type($type); |
| 161 | 161 | $id = (int) $ref; |
| 162 | - $ref = $type . $ref; |
|
| 162 | + $ref = $type.$ref; |
|
| 163 | 163 | } |
| 164 | 164 | else { |
| 165 | 165 | // Si la référence ne correspond à rien, c'est fini |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | return json_export(false); |
| 168 | 168 | } |
| 169 | 169 | // Sinon on récupère les infos utiles |
| 170 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 170 | + [$type,, $id,,,,] = array_pad($match, 7, null); |
|
| 171 | 171 | |
| 172 | 172 | // On regarde si le type trouvé fait partie des objets sélectionnables |
| 173 | 173 | if (!in_array(table_objet($type), $objets)) { |
@@ -213,8 +213,8 @@ discard block |
||
| 213 | 213 | $types = (is_array($types) ? array_filter($types) : []); |
| 214 | 214 | |
| 215 | 215 | // recuperer tous les freres et soeurs de la rubrique visee |
| 216 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 216 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 217 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent='.(int) $id_parent); |
|
| 218 | 218 | $fratrie = array_column($fratrie, 'id_rubrique'); |
| 219 | 219 | $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
| 220 | 220 | $has = array_column($has, 'id_parent'); |
@@ -160,8 +160,7 @@ |
||
| 160 | 160 | $type = objet_type($type); |
| 161 | 161 | $id = (int) $ref; |
| 162 | 162 | $ref = $type . $ref; |
| 163 | - } |
|
| 164 | - else { |
|
| 163 | + } else { |
|
| 165 | 164 | // Si la référence ne correspond à rien, c'est fini |
| 166 | 165 | if (!($match = typer_raccourci($ref))) { |
| 167 | 166 | return json_export(false); |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | **/ |
| 8 | 8 | |
| 9 | 9 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -28,49 +28,49 @@ discard block |
||
| 28 | 28 | * - afficher : tableau des objets à afficher (mais pas forcément sélectionnables) |
| 29 | 29 | */ |
| 30 | 30 | function selecteur_lister_objets($includelist = [], $excludelist = []) { |
| 31 | - static $liste_selecteurs, $liste_parents; |
|
| 32 | - |
|
| 33 | - if (!$liste_selecteurs) { |
|
| 34 | - $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | - } |
|
| 36 | - $objets_selectionner = []; |
|
| 37 | - foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | - $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | - if (!empty($includelist)) { |
|
| 43 | - $includelist = array_map('table_objet', $includelist); |
|
| 44 | - $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | - } |
|
| 46 | - // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | - $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | - // On enlève toujours la racine |
|
| 49 | - $excludelist[] = 'racine'; |
|
| 50 | - $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | - |
|
| 52 | - // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | - $objets_afficher = $objets_selectionner; |
|
| 54 | - |
|
| 55 | - // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | - // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | - if (!$liste_parents) { |
|
| 58 | - $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | - } |
|
| 60 | - foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | - preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | - $parent = $captures[1]; |
|
| 63 | - $type = $captures[2]; |
|
| 64 | - // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | - if (in_array($type, $objets_afficher)) { |
|
| 66 | - $objets_afficher[] = $parent; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return [ |
|
| 71 | - 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | - 'afficher' => array_unique($objets_afficher), |
|
| 73 | - ]; |
|
| 31 | + static $liste_selecteurs, $liste_parents; |
|
| 32 | + |
|
| 33 | + if (!$liste_selecteurs) { |
|
| 34 | + $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | + } |
|
| 36 | + $objets_selectionner = []; |
|
| 37 | + foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | + $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | + if (!empty($includelist)) { |
|
| 43 | + $includelist = array_map('table_objet', $includelist); |
|
| 44 | + $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | + } |
|
| 46 | + // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | + $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | + // On enlève toujours la racine |
|
| 49 | + $excludelist[] = 'racine'; |
|
| 50 | + $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | + |
|
| 52 | + // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | + $objets_afficher = $objets_selectionner; |
|
| 54 | + |
|
| 55 | + // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | + // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | + if (!$liste_parents) { |
|
| 58 | + $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | + } |
|
| 60 | + foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | + preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | + $parent = $captures[1]; |
|
| 63 | + $type = $captures[2]; |
|
| 64 | + // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | + if (in_array($type, $objets_afficher)) { |
|
| 66 | + $objets_afficher[] = $parent; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return [ |
|
| 71 | + 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | + 'afficher' => array_unique($objets_afficher), |
|
| 73 | + ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -97,31 +97,31 @@ discard block |
||
| 97 | 97 | * liste des couples (objets => id_objet) ou liste des identifiants d'un type d'objet. |
| 98 | 98 | **/ |
| 99 | 99 | function picker_selected($selected, $type = '') { |
| 100 | - $select = []; |
|
| 101 | - $type = preg_replace(',\W,', '', $type); |
|
| 102 | - |
|
| 103 | - if ($selected && !is_array($selected)) { |
|
| 104 | - $selected = explode(',', $selected); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if (is_array($selected)) { |
|
| 108 | - foreach ($selected as $value) { |
|
| 109 | - // Si c'est le bon format déjà |
|
| 110 | - if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | - $objet = $captures[1]; |
|
| 112 | - $id_objet = (int) $captures[2]; |
|
| 113 | - |
|
| 114 | - // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | - if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | - $select[] = $id_objet; |
|
| 117 | - } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | - $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $select; |
|
| 100 | + $select = []; |
|
| 101 | + $type = preg_replace(',\W,', '', $type); |
|
| 102 | + |
|
| 103 | + if ($selected && !is_array($selected)) { |
|
| 104 | + $selected = explode(',', $selected); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if (is_array($selected)) { |
|
| 108 | + foreach ($selected as $value) { |
|
| 109 | + // Si c'est le bon format déjà |
|
| 110 | + if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | + $objet = $captures[1]; |
|
| 112 | + $id_objet = (int) $captures[2]; |
|
| 113 | + |
|
| 114 | + // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | + if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | + $select[] = $id_objet; |
|
| 117 | + } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | + $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $select; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -138,53 +138,53 @@ discard block |
||
| 138 | 138 | * Booléen indiquant si les articles sont sélectionnables |
| 139 | 139 | */ |
| 140 | 140 | function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false) { |
| 141 | - include_spip('inc/json'); |
|
| 142 | - include_spip('inc/lien'); |
|
| 143 | - |
|
| 144 | - // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | - $objets = []; |
|
| 146 | - if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | - $objets = $rubriques_ou_objets; |
|
| 148 | - } else { |
|
| 149 | - if ($rubriques_ou_objets) { |
|
| 150 | - $objets[] = 'rubriques'; |
|
| 151 | - } |
|
| 152 | - if ($articles) { |
|
| 153 | - $objets[] = 'articles'; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | - if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | - $type = reset($objets); |
|
| 160 | - $type = objet_type($type); |
|
| 161 | - $id = (int) $ref; |
|
| 162 | - $ref = $type . $ref; |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - // Si la référence ne correspond à rien, c'est fini |
|
| 166 | - if (!($match = typer_raccourci($ref))) { |
|
| 167 | - return json_export(false); |
|
| 168 | - } |
|
| 169 | - // Sinon on récupère les infos utiles |
|
| 170 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | - |
|
| 172 | - // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | - if (!in_array(table_objet($type), $objets)) { |
|
| 174 | - return json_export(false); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | - include_spip('inc/filtres'); |
|
| 180 | - if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | - return json_export(false); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // On simplifie le texte |
|
| 185 | - $titre = attribut_html($titre); |
|
| 186 | - |
|
| 187 | - return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 141 | + include_spip('inc/json'); |
|
| 142 | + include_spip('inc/lien'); |
|
| 143 | + |
|
| 144 | + // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | + $objets = []; |
|
| 146 | + if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | + $objets = $rubriques_ou_objets; |
|
| 148 | + } else { |
|
| 149 | + if ($rubriques_ou_objets) { |
|
| 150 | + $objets[] = 'rubriques'; |
|
| 151 | + } |
|
| 152 | + if ($articles) { |
|
| 153 | + $objets[] = 'articles'; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | + if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | + $type = reset($objets); |
|
| 160 | + $type = objet_type($type); |
|
| 161 | + $id = (int) $ref; |
|
| 162 | + $ref = $type . $ref; |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + // Si la référence ne correspond à rien, c'est fini |
|
| 166 | + if (!($match = typer_raccourci($ref))) { |
|
| 167 | + return json_export(false); |
|
| 168 | + } |
|
| 169 | + // Sinon on récupère les infos utiles |
|
| 170 | + [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | + |
|
| 172 | + // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | + if (!in_array(table_objet($type), $objets)) { |
|
| 174 | + return json_export(false); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | + include_spip('inc/filtres'); |
|
| 180 | + if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | + return json_export(false); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // On simplifie le texte |
|
| 185 | + $titre = attribut_html($titre); |
|
| 186 | + |
|
| 187 | + return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -207,34 +207,34 @@ discard block |
||
| 207 | 207 | * Comme le filtre `oui` : espace (` `) si rubrique à afficher, chaîne vide sinon. |
| 208 | 208 | */ |
| 209 | 209 | function test_enfants_rubrique($id_rubrique, $types = []) { |
| 210 | - static $has_child = []; |
|
| 211 | - |
|
| 212 | - if (!isset($has_child[$id_rubrique])) { |
|
| 213 | - $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | - |
|
| 215 | - // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | - $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | - $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | - $has = array_column($has, 'id_parent'); |
|
| 221 | - $fratrie = array_diff($fratrie, $has); |
|
| 222 | - |
|
| 223 | - while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | - $type = array_shift($types); |
|
| 225 | - $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | - $h = array_column($h, 'id_rubrique'); |
|
| 227 | - $has = [...$has, ...$h]; |
|
| 228 | - $fratrie = array_diff($fratrie, $h); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - if ($has !== []) { |
|
| 232 | - $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | - } |
|
| 234 | - if ($fratrie !== []) { |
|
| 235 | - $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 210 | + static $has_child = []; |
|
| 211 | + |
|
| 212 | + if (!isset($has_child[$id_rubrique])) { |
|
| 213 | + $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | + |
|
| 215 | + // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | + $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | + $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | + $has = array_column($has, 'id_parent'); |
|
| 221 | + $fratrie = array_diff($fratrie, $has); |
|
| 222 | + |
|
| 223 | + while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | + $type = array_shift($types); |
|
| 225 | + $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | + $h = array_column($h, 'id_rubrique'); |
|
| 227 | + $has = [...$has, ...$h]; |
|
| 228 | + $fratrie = array_diff($fratrie, $h); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + if ($has !== []) { |
|
| 232 | + $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | + } |
|
| 234 | + if ($fratrie !== []) { |
|
| 235 | + $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 240 | 240 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | 29 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 30 | - return; |
|
| 30 | + return; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -47,55 +47,55 @@ discard block |
||
| 47 | 47 | * array : description des roles applicables dans 3 index : colonne, titres, roles |
| 48 | 48 | **/ |
| 49 | 49 | function roles_presents($objet, $objet_destination = '') { |
| 50 | - $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 51 | - |
|
| 52 | - // pas de liste de roles, on sort |
|
| 53 | - if (!isset($desc['roles_titres']) || !($titres = $desc['roles_titres'])) { |
|
| 54 | - return false; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - // on vérifie que la table de liaison existe |
|
| 58 | - include_spip('action/editer_liens'); |
|
| 59 | - if (!$lien = objet_associable($objet)) { |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 64 | - $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 65 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 66 | - [, $table_lien] = $lien; |
|
| 67 | - $desc_lien = $trouver_table($table_lien); |
|
| 68 | - if (!isset($desc_lien['field'][$colonne])) { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // sur quoi peuvent s'appliquer nos rôles |
|
| 73 | - if (!$application = $desc['roles_objets']) { |
|
| 74 | - return false; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // destination presente, on restreint si possible |
|
| 78 | - if ($objet_destination) { |
|
| 79 | - $objet_destination = table_objet($objet_destination); |
|
| 80 | - |
|
| 81 | - // pour l'objet |
|
| 82 | - if (isset($application[$objet_destination])) { |
|
| 83 | - $application = $application[$objet_destination]; |
|
| 84 | - // sinon pour tous les objets |
|
| 85 | - } elseif (isset($application['*'])) { |
|
| 86 | - $application = $application['*']; |
|
| 87 | - } // sinon tant pis |
|
| 88 | - else { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // tout est ok |
|
| 94 | - return [ |
|
| 95 | - 'titres' => $titres, |
|
| 96 | - 'roles' => $application, |
|
| 97 | - 'colonne' => $colonne |
|
| 98 | - ]; |
|
| 50 | + $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 51 | + |
|
| 52 | + // pas de liste de roles, on sort |
|
| 53 | + if (!isset($desc['roles_titres']) || !($titres = $desc['roles_titres'])) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + // on vérifie que la table de liaison existe |
|
| 58 | + include_spip('action/editer_liens'); |
|
| 59 | + if (!$lien = objet_associable($objet)) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 64 | + $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 65 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 66 | + [, $table_lien] = $lien; |
|
| 67 | + $desc_lien = $trouver_table($table_lien); |
|
| 68 | + if (!isset($desc_lien['field'][$colonne])) { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // sur quoi peuvent s'appliquer nos rôles |
|
| 73 | + if (!$application = $desc['roles_objets']) { |
|
| 74 | + return false; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // destination presente, on restreint si possible |
|
| 78 | + if ($objet_destination) { |
|
| 79 | + $objet_destination = table_objet($objet_destination); |
|
| 80 | + |
|
| 81 | + // pour l'objet |
|
| 82 | + if (isset($application[$objet_destination])) { |
|
| 83 | + $application = $application[$objet_destination]; |
|
| 84 | + // sinon pour tous les objets |
|
| 85 | + } elseif (isset($application['*'])) { |
|
| 86 | + $application = $application['*']; |
|
| 87 | + } // sinon tant pis |
|
| 88 | + else { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // tout est ok |
|
| 94 | + return [ |
|
| 95 | + 'titres' => $titres, |
|
| 96 | + 'roles' => $application, |
|
| 97 | + 'colonne' => $colonne |
|
| 98 | + ]; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | * Nom de la colonne, sinon vide |
| 110 | 110 | **/ |
| 111 | 111 | function roles_colonne($objet, $objet_destination) { |
| 112 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 113 | - return $roles['colonne']; |
|
| 114 | - } |
|
| 112 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 113 | + return $roles['colonne']; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - return ''; |
|
| 116 | + return ''; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | |
@@ -135,21 +135,21 @@ discard block |
||
| 135 | 135 | * Liste ('', '', array()) sinon. |
| 136 | 136 | **/ |
| 137 | 137 | function roles_trouver_dans_qualif($objet, $objet_destination, $qualif = []) { |
| 138 | - // si des rôles sont possibles, on les utilise |
|
| 139 | - $role = $colonne_role = ''; # role défini |
|
| 140 | - // condition du where par defaut |
|
| 141 | - $cond = []; |
|
| 142 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 143 | - $colonne_role = $roles['colonne']; |
|
| 144 | - // qu'il n'est pas défini |
|
| 145 | - if (!isset($qualif[$colonne_role]) || !($role = $qualif[$colonne_role])) { |
|
| 146 | - $role = $roles['roles']['defaut']; |
|
| 147 | - } |
|
| 148 | - // where |
|
| 149 | - $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return [$role, $colonne_role, $cond]; |
|
| 138 | + // si des rôles sont possibles, on les utilise |
|
| 139 | + $role = $colonne_role = ''; # role défini |
|
| 140 | + // condition du where par defaut |
|
| 141 | + $cond = []; |
|
| 142 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 143 | + $colonne_role = $roles['colonne']; |
|
| 144 | + // qu'il n'est pas défini |
|
| 145 | + if (!isset($qualif[$colonne_role]) || !($role = $qualif[$colonne_role])) { |
|
| 146 | + $role = $roles['roles']['defaut']; |
|
| 147 | + } |
|
| 148 | + // where |
|
| 149 | + $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return [$role, $colonne_role, $cond]; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -171,18 +171,18 @@ discard block |
||
| 171 | 171 | * Liste (Tableau de conditions where complété du role, Colonne du role, role utilisé) |
| 172 | 172 | **/ |
| 173 | 173 | function roles_creer_condition_role($objet_source, $objet, $cond, $tous_si_absent = false) { |
| 174 | - // role par défaut, colonne |
|
| 175 | - [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 176 | - |
|
| 177 | - // chercher d'eventuels rôles transmis |
|
| 178 | - $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 179 | - unset($cond['role']); // cette condition est particuliere... |
|
| 180 | - // on ajoute la condition du role aux autres conditions. |
|
| 181 | - if ($colonne_role && $role != '*') { |
|
| 182 | - $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - return [$cond, $colonne_role, $role]; |
|
| 174 | + // role par défaut, colonne |
|
| 175 | + [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 176 | + |
|
| 177 | + // chercher d'eventuels rôles transmis |
|
| 178 | + $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 179 | + unset($cond['role']); // cette condition est particuliere... |
|
| 180 | + // on ajoute la condition du role aux autres conditions. |
|
| 181 | + if ($colonne_role && $role != '*') { |
|
| 182 | + $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + return [$cond, $colonne_role, $role]; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -204,28 +204,28 @@ discard block |
||
| 204 | 204 | */ |
| 205 | 205 | function roles_complets($objet_source, $objet, $id_objet, $objet_lien) { |
| 206 | 206 | |
| 207 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 208 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 209 | - if ($presents === false) { |
|
| 210 | - return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - // types de roles possibles |
|
| 214 | - $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 215 | - // couples id / roles |
|
| 216 | - $ids = $presents['ids']; |
|
| 217 | - |
|
| 218 | - // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 219 | - // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 220 | - // n'est pas complet |
|
| 221 | - $complets = []; |
|
| 222 | - foreach ($ids as $id => $roles_presents) { |
|
| 223 | - if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 224 | - $complets[] = $id; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return $complets; |
|
| 207 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 208 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 209 | + if ($presents === false) { |
|
| 210 | + return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + // types de roles possibles |
|
| 214 | + $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 215 | + // couples id / roles |
|
| 216 | + $ids = $presents['ids']; |
|
| 217 | + |
|
| 218 | + // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 219 | + // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 220 | + // n'est pas complet |
|
| 221 | + $complets = []; |
|
| 222 | + foreach ($ids as $id => $roles_presents) { |
|
| 223 | + if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 224 | + $complets[] = $id; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return $complets; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | |
@@ -242,17 +242,17 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | function roles_presents_sur_id($id_objet_source, $objet_source, $objet, $id_objet, $objet_lien) { |
| 244 | 244 | |
| 245 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 246 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 247 | - if ($presents === false) { |
|
| 248 | - return []; |
|
| 249 | - } |
|
| 245 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 246 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 247 | + if ($presents === false) { |
|
| 248 | + return []; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - if (!isset($presents['ids'][$id_objet_source])) { |
|
| 252 | - return []; |
|
| 253 | - } |
|
| 251 | + if (!isset($presents['ids'][$id_objet_source])) { |
|
| 252 | + return []; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - return $presents['ids'][$id_objet_source]; |
|
| 255 | + return $presents['ids'][$id_objet_source]; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | |
@@ -280,47 +280,47 @@ discard block |
||
| 280 | 280 | * - False si pas de role déclarés |
| 281 | 281 | */ |
| 282 | 282 | function roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien) { |
| 283 | - static $done = []; |
|
| 284 | - |
|
| 285 | - // stocker le résultat |
|
| 286 | - $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 287 | - if (isset($done[$hash])) { |
|
| 288 | - return $done[$hash]; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // pas de roles sur ces objets, on sort |
|
| 292 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 293 | - if (!$roles) { |
|
| 294 | - return $done[$hash] = false; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // inspiré de lister_objets_lies() |
|
| 298 | - if ($objet_lien == $objet) { |
|
| 299 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 300 | - } else { |
|
| 301 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // types de roles possibles |
|
| 305 | - $roles_possibles = $roles['roles']['choix']; |
|
| 306 | - // colonne du role |
|
| 307 | - $colonne = $roles['colonne']; |
|
| 308 | - |
|
| 309 | - // on recupere par id, et role existant |
|
| 310 | - $ids = []; |
|
| 311 | - while ($row = array_shift($res)) { |
|
| 312 | - $id = $row[$objet_source]; |
|
| 313 | - if (!isset($ids[$id])) { |
|
| 314 | - $ids[$id] = []; |
|
| 315 | - } |
|
| 316 | - // tableau des roles présents |
|
| 317 | - $ids[$id][] = $row[$colonne]; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - return $done[$hash] = [ |
|
| 321 | - 'roles' => $roles, |
|
| 322 | - 'ids' => $ids |
|
| 323 | - ]; |
|
| 283 | + static $done = []; |
|
| 284 | + |
|
| 285 | + // stocker le résultat |
|
| 286 | + $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 287 | + if (isset($done[$hash])) { |
|
| 288 | + return $done[$hash]; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // pas de roles sur ces objets, on sort |
|
| 292 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 293 | + if (!$roles) { |
|
| 294 | + return $done[$hash] = false; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // inspiré de lister_objets_lies() |
|
| 298 | + if ($objet_lien == $objet) { |
|
| 299 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 300 | + } else { |
|
| 301 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // types de roles possibles |
|
| 305 | + $roles_possibles = $roles['roles']['choix']; |
|
| 306 | + // colonne du role |
|
| 307 | + $colonne = $roles['colonne']; |
|
| 308 | + |
|
| 309 | + // on recupere par id, et role existant |
|
| 310 | + $ids = []; |
|
| 311 | + while ($row = array_shift($res)) { |
|
| 312 | + $id = $row[$objet_source]; |
|
| 313 | + if (!isset($ids[$id])) { |
|
| 314 | + $ids[$id] = []; |
|
| 315 | + } |
|
| 316 | + // tableau des roles présents |
|
| 317 | + $ids[$id][] = $row[$colonne]; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + return $done[$hash] = [ |
|
| 321 | + 'roles' => $roles, |
|
| 322 | + 'ids' => $ids |
|
| 323 | + ]; |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | |
@@ -338,33 +338,33 @@ discard block |
||
| 338 | 338 | * - false si pas de role déclarés |
| 339 | 339 | */ |
| 340 | 340 | function roles_connus_en_base($objet_source, $objet, $objet_lien) { |
| 341 | - static $done = []; |
|
| 342 | - |
|
| 343 | - // stocker le résultat |
|
| 344 | - $hash = "$objet_source-$objet-$objet_lien"; |
|
| 345 | - if (isset($done[$hash])) { |
|
| 346 | - return $done[$hash]; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if (!$lien = objet_associable($objet_lien)) { |
|
| 350 | - return $done[$hash] = false; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - // pas de roles sur ces objets, on sort |
|
| 354 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 355 | - if (!$roles) { |
|
| 356 | - return $done[$hash] = false; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - [$primary, $l] = $lien; |
|
| 360 | - $colone_role = $roles['colonne']; |
|
| 361 | - |
|
| 362 | - $all = sql_allfetsel( |
|
| 363 | - "DISTINCT $colone_role", |
|
| 364 | - $l, |
|
| 365 | - 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 366 | - ); |
|
| 367 | - $done[$hash] = array_map('reset', $all); |
|
| 368 | - |
|
| 369 | - return $done[$hash]; |
|
| 341 | + static $done = []; |
|
| 342 | + |
|
| 343 | + // stocker le résultat |
|
| 344 | + $hash = "$objet_source-$objet-$objet_lien"; |
|
| 345 | + if (isset($done[$hash])) { |
|
| 346 | + return $done[$hash]; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if (!$lien = objet_associable($objet_lien)) { |
|
| 350 | + return $done[$hash] = false; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + // pas de roles sur ces objets, on sort |
|
| 354 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 355 | + if (!$roles) { |
|
| 356 | + return $done[$hash] = false; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + [$primary, $l] = $lien; |
|
| 360 | + $colone_role = $roles['colonne']; |
|
| 361 | + |
|
| 362 | + $all = sql_allfetsel( |
|
| 363 | + "DISTINCT $colone_role", |
|
| 364 | + $l, |
|
| 365 | + 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 366 | + ); |
|
| 367 | + $done[$hash] = array_map('reset', $all); |
|
| 368 | + |
|
| 369 | + return $done[$hash]; |
|
| 370 | 370 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $role = $roles['roles']['defaut']; |
| 147 | 147 | } |
| 148 | 148 | // where |
| 149 | - $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 149 | + $cond = ["$colonne_role=".sql_quote($role)]; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | return [$role, $colonne_role, $cond]; |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | unset($cond['role']); // cette condition est particuliere... |
| 180 | 180 | // on ajoute la condition du role aux autres conditions. |
| 181 | 181 | if ($colonne_role && $role != '*') { |
| 182 | - $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 182 | + $cond[] = "$colonne_role=".sql_quote($role); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | return [$cond, $colonne_role, $role]; |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | $all = sql_allfetsel( |
| 363 | 363 | "DISTINCT $colone_role", |
| 364 | 364 | $l, |
| 365 | - 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 365 | + 'objet='.sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 366 | 366 | ); |
| 367 | 367 | $done[$hash] = array_map('reset', $all); |
| 368 | 368 | |