@@ -802,8 +802,7 @@ discard block |
||
| 802 | 802 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 803 | 803 | if (is_null($fin)) { |
| 804 | 804 | return substr_count($texte, "\n", $debut); |
| 805 | - } |
|
| 806 | - else { |
|
| 805 | + } else { |
|
| 807 | 806 | return substr_count($texte, "\n", $debut, $fin - $debut); |
| 808 | 807 | } |
| 809 | 808 | } |
@@ -850,8 +849,7 @@ discard block |
||
| 850 | 849 | erreur_squelette($err_b, $result); |
| 851 | 850 | |
| 852 | 851 | continue; |
| 853 | - } |
|
| 854 | - else { |
|
| 852 | + } else { |
|
| 855 | 853 | $boucle = [ |
| 856 | 854 | 'id_boucle' => $id_boucle, |
| 857 | 855 | 'id_boucle_err' => $id_boucle, |
@@ -991,8 +989,7 @@ discard block |
||
| 991 | 989 | // si c'est un appel pour memoriser une boucle, memorisons la |
| 992 | 990 | if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
| 993 | 991 | $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
| 994 | - } |
|
| 995 | - else { |
|
| 992 | + } else { |
|
| 996 | 993 | if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
| 997 | 994 | $placeholder = $champ->nom_champ; |
| 998 | 995 | $id = reset($champ->param[0][1]); |
@@ -1135,8 +1132,7 @@ discard block |
||
| 1135 | 1132 | ]; |
| 1136 | 1133 | erreur_squelette($err_b, $result); |
| 1137 | 1134 | $pos_courante += strlen($fin_boucle); |
| 1138 | - } |
|
| 1139 | - else { |
|
| 1135 | + } else { |
|
| 1140 | 1136 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1141 | 1137 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1142 | 1138 | $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
@@ -48,19 +48,19 @@ discard block |
||
| 48 | 48 | * Nom d'une balise #TOTO |
| 49 | 49 | * |
| 50 | 50 | * Écriture alambiquée pour rester compatible avec les hexadecimaux des vieux squelettes */ |
| 51 | -define('NOM_DE_CHAMP', '#((' . NOM_DE_BOUCLE . "):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 51 | +define('NOM_DE_CHAMP', '#(('.NOM_DE_BOUCLE."):)?(([A-F]*[G-Z_][A-Z_0-9]*)|[A-Z_]+)\b(\*{0,2})"); |
|
| 52 | 52 | /** Balise complète [...(#TOTO) ... ] */ |
| 53 | -define('CHAMP_ETENDU', '/\[([^]\[]*)\(' . NOM_DE_CHAMP . '([^[)]*\)[^]\[]*)\]/S'); |
|
| 53 | +define('CHAMP_ETENDU', '/\[([^]\[]*)\('.NOM_DE_CHAMP.'([^[)]*\)[^]\[]*)\]/S'); |
|
| 54 | 54 | |
| 55 | 55 | define('BALISE_INCLURE', '/<INCLU[DR]E[[:space:]]*(\(([^)]*)\))?/S'); |
| 56 | 56 | define('BALISE_POLYGLOTTE', ',<multi>(.*)</multi>,Uims'); |
| 57 | 57 | define('BALISE_IDIOMES', ',<:(([a-z0-9_]+):)?([a-z0-9_]*)({([^\|=>]*=[^\|>]*)})?((\|[^>]*)?:/?>),iS'); |
| 58 | -define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*((' . NOM_DE_CHAMP . '[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 58 | +define('BALISE_IDIOMES_ARGS', '@^\s*([^= ]*)\s*=\s*(('.NOM_DE_CHAMP.'[{][^}]*})?[^,]*)\s*,?\s*@s'); |
|
| 59 | 59 | |
| 60 | 60 | /** Champ sql dans parenthèse ex: (id_article) */ |
| 61 | 61 | define('SQL_ARGS', '(\([^)]*\))'); |
| 62 | 62 | /** Fonction SQL sur un champ ex: SUM(visites) */ |
| 63 | -define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)' . SQL_ARGS . '?`?'); |
|
| 63 | +define('CHAMP_SQL_PLUS_FONC', '`?([A-Z_\/][A-Z_\/0-9.]*)'.SQL_ARGS.'?`?'); |
|
| 64 | 64 | |
| 65 | 65 | function phraser_inclure($texte, $ligne, $result) { |
| 66 | 66 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | * @return array |
| 216 | 216 | **/ |
| 217 | 217 | function phraser_champs($texte, $ligne, $result) { |
| 218 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 218 | + while (preg_match('/'.NOM_DE_CHAMP.'/S', $texte, $match)) { |
|
| 219 | 219 | $p = strpos($texte, (string) $match[0]); |
| 220 | 220 | // texte après la balise |
| 221 | 221 | $suite = substr($texte, $p + strlen($match[0])); |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | $collecte[] = $champ; |
| 364 | 364 | $args = ltrim($regs[count($regs) - 1]); |
| 365 | 365 | } else { |
| 366 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 366 | + if (!preg_match('/'.NOM_DE_CHAMP.'([{|])/', $arg, $r)) { |
|
| 367 | 367 | // 0 est un aveu d'impuissance. A completer |
| 368 | 368 | $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
| 369 | 369 | |
@@ -447,7 +447,7 @@ discard block |
||
| 447 | 447 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 448 | 448 | $res = []; |
| 449 | 449 | while (($p = strpos($texte, (string) "%$sep")) !== false) { |
| 450 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 450 | + if (!preg_match(',^%'.preg_quote($sep).'([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 451 | 451 | break; |
| 452 | 452 | } |
| 453 | 453 | $debut = substr($texte, 0, $p); |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | $pos_apres = 0; |
| 488 | 488 | $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
| 489 | 489 | phraser_vieux($champ); |
| 490 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 490 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | 491 | $debut = substr($match[7], $pos_apres + 1); |
| 492 | 492 | if (!empty($debut)) { |
| 493 | 493 | $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
@@ -618,7 +618,7 @@ discard block |
||
| 618 | 618 | // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
| 619 | 619 | if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
| 620 | 620 | $c = null; |
| 621 | - eval('$c = ' . $m[4] . ';'); |
|
| 621 | + eval('$c = '.$m[4].';'); |
|
| 622 | 622 | if (isset($c)) { |
| 623 | 623 | $m[4] = $c; |
| 624 | 624 | } |
@@ -698,7 +698,7 @@ discard block |
||
| 698 | 698 | if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
| 699 | 699 | $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
| 700 | 700 | } elseif ( |
| 701 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 701 | + preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC. |
|
| 702 | 702 | ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
| 703 | 703 | ) { |
| 704 | 704 | $a2 = trim($m[8]); |
@@ -715,8 +715,8 @@ discard block |
||
| 715 | 715 | ); |
| 716 | 716 | $crit->exclus = $m[1]; |
| 717 | 717 | } elseif ( |
| 718 | - preg_match('/^([!]?)\s*(' . |
|
| 719 | - CHAMP_SQL_PLUS_FONC . |
|
| 718 | + preg_match('/^([!]?)\s*('. |
|
| 719 | + CHAMP_SQL_PLUS_FONC. |
|
| 720 | 720 | ')\s*(\??)(.*)$/is', $param, $m) |
| 721 | 721 | ) { |
| 722 | 722 | // contient aussi les comparaisons implicites ! |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
| 864 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 864 | + $precond_boucle = BALISE_PRECOND_BOUCLE.$id_boucle.'>'; |
|
| 865 | 865 | $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 866 | 866 | if ( |
| 867 | 867 | $pos_precond !== false |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 875 | + $preaff_boucle = BALISE_PREAFF_BOUCLE.$id_boucle.'>'; |
|
| 876 | 876 | $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
| 877 | 877 | if ( |
| 878 | 878 | $pos_preaff !== false |
@@ -920,13 +920,13 @@ discard block |
||
| 920 | 920 | $pos_anonyme_next = null; |
| 921 | 921 | // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
| 922 | 922 | if (!strlen($id_boucle)) { |
| 923 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 923 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE.'(', $pos_courante); |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | // |
| 927 | 927 | // 1. Recuperer la partie conditionnelle apres |
| 928 | 928 | // |
| 929 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 929 | + $apres_boucle = BALISE_POSTCOND_BOUCLE.$id_boucle.'>'; |
|
| 930 | 930 | $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
| 931 | 931 | if ( |
| 932 | 932 | $pos_apres !== false |
@@ -935,13 +935,13 @@ discard block |
||
| 935 | 935 | $boucle['pos_postcond'] = $pos_apres; |
| 936 | 936 | $pos_apres += strlen($apres_boucle); |
| 937 | 937 | $boucle['pos_postcond_inside'] = $pos_apres; |
| 938 | - $pos_courante = $pos_apres ; |
|
| 938 | + $pos_courante = $pos_apres; |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | // |
| 942 | 942 | // 2. Récuperer la partie alternative apres |
| 943 | 943 | // |
| 944 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 944 | + $altern_boucle = BALISE_ALT_BOUCLE.$id_boucle.'>'; |
|
| 945 | 945 | $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
| 946 | 946 | if ( |
| 947 | 947 | $pos_altern !== false |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | // |
| 957 | 957 | // 3. Recuperer la partie footer non alternative |
| 958 | 958 | // |
| 959 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 959 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE.$id_boucle.'>'; |
|
| 960 | 960 | $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
| 961 | 961 | if ( |
| 962 | 962 | $pos_postaff !== false |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | $boucle['pos_postaff'] = $pos_postaff; |
| 966 | 966 | $pos_postaff += strlen($postaff_boucle); |
| 967 | 967 | $boucle['pos_postaff_inside'] = $pos_postaff; |
| 968 | - $pos_courante = $pos_postaff ; |
|
| 968 | + $pos_courante = $pos_postaff; |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | return $boucle; |
@@ -1005,7 +1005,7 @@ discard block |
||
| 1005 | 1005 | * @return string |
| 1006 | 1006 | */ |
| 1007 | 1007 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1008 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1008 | + $placeholder = "[(#{$boucle_placeholder}{".$id_boucle.'})'.str_pad('', $nb_lignes, "\n").']'; |
|
| 1009 | 1009 | //memoriser la boucle a reinjecter |
| 1010 | 1010 | $id_boucle = "$id_boucle"; |
| 1011 | 1011 | phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
@@ -1018,7 +1018,7 @@ discard block |
||
| 1018 | 1018 | // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
| 1019 | 1019 | if (is_null($boucle_placeholder)) { |
| 1020 | 1020 | do { |
| 1021 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1021 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_'.strtoupper(md5(uniqid())); |
|
| 1022 | 1022 | } while (strpos($texte, $boucle_placeholder) !== false); |
| 1023 | 1023 | } |
| 1024 | 1024 | |
@@ -1038,7 +1038,7 @@ discard block |
||
| 1038 | 1038 | |
| 1039 | 1039 | // boucle anonyme ? |
| 1040 | 1040 | if (!strlen($id_boucle)) { |
| 1041 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1041 | + $id_boucle = '_anon_L'.$ligne_milieu.'_'.substr(md5('anonyme:'.$id_parent.':'.json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | $pos_debut_boucle = $pos_courante; |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | |
| 1052 | 1052 | $pos_avant = $boucle['pos_precond_inside']; |
| 1053 | 1053 | $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
| 1054 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1054 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
@@ -1060,7 +1060,7 @@ discard block |
||
| 1060 | 1060 | |
| 1061 | 1061 | $pos_preaff = $boucle['pos_preaff_inside']; |
| 1062 | 1062 | $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
| 1063 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1063 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | $result->id_boucle = $id_boucle; |
@@ -1117,7 +1117,7 @@ discard block |
||
| 1117 | 1117 | } else { |
| 1118 | 1118 | $pos_milieu += 1; |
| 1119 | 1119 | |
| 1120 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1120 | + $fin_boucle = BALISE_FIN_BOUCLE.$id_boucle_search.'>'; |
|
| 1121 | 1121 | $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
| 1122 | 1122 | if ($pos_fin === false) { |
| 1123 | 1123 | $err_b = [ |
@@ -1130,7 +1130,7 @@ discard block |
||
| 1130 | 1130 | else { |
| 1131 | 1131 | // verifier une eventuelle imbrication d'une boucle homonyme |
| 1132 | 1132 | // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
| 1133 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1133 | + $search_debut_boucle = BALISE_BOUCLE.$id_boucle_search.'('; |
|
| 1134 | 1134 | $search_from = $pos_milieu; |
| 1135 | 1135 | $nb_open = 1; |
| 1136 | 1136 | $nb_close = 1; |
@@ -1170,7 +1170,7 @@ discard block |
||
| 1170 | 1170 | if ($boucle['pos_postcond']) { |
| 1171 | 1171 | $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
| 1172 | 1172 | $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
| 1173 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1173 | + $pos_courante = $boucle['pos_postcond_inside']; |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | **/ |
| 29 | 29 | |
| 30 | 30 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 31 | - return; |
|
| 31 | + return; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** Début de la partie principale d'une boucle */ |
@@ -72,82 +72,82 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | function phraser_inclure($texte, $ligne, $result) { |
| 74 | 74 | |
| 75 | - while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 76 | - $match = array_pad($match, 3, null); |
|
| 77 | - $p = strpos($texte, (string) $match[0]); |
|
| 78 | - $debut = substr($texte, 0, $p); |
|
| 79 | - if ($p) { |
|
| 80 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 81 | - } |
|
| 82 | - $ligne += substr_count($debut, "\n"); |
|
| 83 | - $champ = new Inclure(); |
|
| 84 | - $champ->ligne = $ligne; |
|
| 85 | - $ligne += substr_count($match[0], "\n"); |
|
| 86 | - $fichier = $match[2]; |
|
| 87 | - # assurer ici la migration .php3 => .php |
|
| 88 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 89 | - if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 90 | - $fichier = $r[1]; |
|
| 91 | - } |
|
| 92 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 93 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 94 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 95 | - $pos_apres = 0; |
|
| 96 | - phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 97 | - if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 98 | - if (!function_exists('normaliser_inclure')) { |
|
| 99 | - include_spip('public/normaliser'); |
|
| 100 | - } |
|
| 101 | - normaliser_inclure($champ); |
|
| 102 | - } |
|
| 103 | - $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 104 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 105 | - $result[] = $champ; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 75 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 76 | + $match = array_pad($match, 3, null); |
|
| 77 | + $p = strpos($texte, (string) $match[0]); |
|
| 78 | + $debut = substr($texte, 0, $p); |
|
| 79 | + if ($p) { |
|
| 80 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 81 | + } |
|
| 82 | + $ligne += substr_count($debut, "\n"); |
|
| 83 | + $champ = new Inclure(); |
|
| 84 | + $champ->ligne = $ligne; |
|
| 85 | + $ligne += substr_count($match[0], "\n"); |
|
| 86 | + $fichier = $match[2]; |
|
| 87 | + # assurer ici la migration .php3 => .php |
|
| 88 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 89 | + if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 90 | + $fichier = $r[1]; |
|
| 91 | + } |
|
| 92 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 93 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 94 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 95 | + $pos_apres = 0; |
|
| 96 | + phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 97 | + if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 98 | + if (!function_exists('normaliser_inclure')) { |
|
| 99 | + include_spip('public/normaliser'); |
|
| 100 | + } |
|
| 101 | + normaliser_inclure($champ); |
|
| 102 | + } |
|
| 103 | + $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 104 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 105 | + $result[] = $champ; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | function phraser_polyglotte($texte, $ligne, $result) { |
| 112 | 112 | |
| 113 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 114 | - foreach ($m as $match) { |
|
| 115 | - $p = strpos($texte, (string) $match[0]); |
|
| 116 | - $debut = substr($texte, 0, $p); |
|
| 117 | - if ($p) { |
|
| 118 | - $champ = new Texte(); |
|
| 119 | - $champ->texte = $debut; |
|
| 120 | - $champ->ligne = $ligne; |
|
| 121 | - $result[] = $champ; |
|
| 122 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $champ = new Polyglotte(); |
|
| 126 | - $champ->ligne = $ligne; |
|
| 127 | - $ligne += substr_count($match[0], "\n"); |
|
| 128 | - $lang = ''; |
|
| 129 | - $bloc = $match[1]; |
|
| 130 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 131 | - while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 132 | - $trad = $regs[1]; |
|
| 133 | - if ($trad or $lang) { |
|
| 134 | - $champ->traductions[$lang] = $trad; |
|
| 135 | - } |
|
| 136 | - $lang = $regs[2]; |
|
| 137 | - $bloc = $regs[3]; |
|
| 138 | - } |
|
| 139 | - $champ->traductions[$lang] = $bloc; |
|
| 140 | - $result[] = $champ; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - if ($texte !== '') { |
|
| 144 | - $champ = new Texte(); |
|
| 145 | - $champ->texte = $texte; |
|
| 146 | - $champ->ligne = $ligne; |
|
| 147 | - $result[] = $champ; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $result; |
|
| 113 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 114 | + foreach ($m as $match) { |
|
| 115 | + $p = strpos($texte, (string) $match[0]); |
|
| 116 | + $debut = substr($texte, 0, $p); |
|
| 117 | + if ($p) { |
|
| 118 | + $champ = new Texte(); |
|
| 119 | + $champ->texte = $debut; |
|
| 120 | + $champ->ligne = $ligne; |
|
| 121 | + $result[] = $champ; |
|
| 122 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $champ = new Polyglotte(); |
|
| 126 | + $champ->ligne = $ligne; |
|
| 127 | + $ligne += substr_count($match[0], "\n"); |
|
| 128 | + $lang = ''; |
|
| 129 | + $bloc = $match[1]; |
|
| 130 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 131 | + while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 132 | + $trad = $regs[1]; |
|
| 133 | + if ($trad or $lang) { |
|
| 134 | + $champ->traductions[$lang] = $trad; |
|
| 135 | + } |
|
| 136 | + $lang = $regs[2]; |
|
| 137 | + $bloc = $regs[3]; |
|
| 138 | + } |
|
| 139 | + $champ->traductions[$lang] = $bloc; |
|
| 140 | + $result[] = $champ; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + if ($texte !== '') { |
|
| 144 | + $champ = new Texte(); |
|
| 145 | + $champ->texte = $texte; |
|
| 146 | + $champ->ligne = $ligne; |
|
| 147 | + $result[] = $champ; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $result; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
@@ -169,43 +169,43 @@ discard block |
||
| 169 | 169 | * @return array |
| 170 | 170 | **/ |
| 171 | 171 | function phraser_idiomes($texte, $ligne, $result) { |
| 172 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 173 | - $match = array_pad($match, 8, null); |
|
| 174 | - $p = strpos($texte, (string) $match[0]); |
|
| 175 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 176 | - $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 177 | - if ($debut) { |
|
| 178 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 179 | - } |
|
| 180 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 181 | - $ligne += substr_count($debut, "\n"); |
|
| 182 | - if ($ko) { |
|
| 183 | - continue; |
|
| 184 | - } // faux idiome |
|
| 185 | - $champ = new Idiome(); |
|
| 186 | - $champ->ligne = $ligne; |
|
| 187 | - $ligne += substr_count($match[0], "\n"); |
|
| 188 | - // Stocker les arguments de la balise de traduction |
|
| 189 | - $args = []; |
|
| 190 | - $largs = $match[5]; |
|
| 191 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 192 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 193 | - $largs = substr($largs, strlen($r[0])); |
|
| 194 | - } |
|
| 195 | - $champ->arg = $args; |
|
| 196 | - $champ->nom_champ = strtolower($match[3]); |
|
| 197 | - $champ->module = $match[2]; |
|
| 198 | - // pas d'imbrication pour les filtres sur langue |
|
| 199 | - $pos_apres = 0; |
|
| 200 | - phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 201 | - $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 202 | - $result[] = $champ; |
|
| 203 | - } |
|
| 204 | - if ($texte !== '') { |
|
| 205 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $result; |
|
| 172 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 173 | + $match = array_pad($match, 8, null); |
|
| 174 | + $p = strpos($texte, (string) $match[0]); |
|
| 175 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 176 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 177 | + if ($debut) { |
|
| 178 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 179 | + } |
|
| 180 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 181 | + $ligne += substr_count($debut, "\n"); |
|
| 182 | + if ($ko) { |
|
| 183 | + continue; |
|
| 184 | + } // faux idiome |
|
| 185 | + $champ = new Idiome(); |
|
| 186 | + $champ->ligne = $ligne; |
|
| 187 | + $ligne += substr_count($match[0], "\n"); |
|
| 188 | + // Stocker les arguments de la balise de traduction |
|
| 189 | + $args = []; |
|
| 190 | + $largs = $match[5]; |
|
| 191 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 192 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 193 | + $largs = substr($largs, strlen($r[0])); |
|
| 194 | + } |
|
| 195 | + $champ->arg = $args; |
|
| 196 | + $champ->nom_champ = strtolower($match[3]); |
|
| 197 | + $champ->module = $match[2]; |
|
| 198 | + // pas d'imbrication pour les filtres sur langue |
|
| 199 | + $pos_apres = 0; |
|
| 200 | + phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 201 | + $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 202 | + $result[] = $champ; |
|
| 203 | + } |
|
| 204 | + if ($texte !== '') { |
|
| 205 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $result; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -223,47 +223,47 @@ discard block |
||
| 223 | 223 | * @return array |
| 224 | 224 | **/ |
| 225 | 225 | function phraser_champs($texte, $ligne, $result) { |
| 226 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 227 | - $p = strpos($texte, (string) $match[0]); |
|
| 228 | - // texte après la balise |
|
| 229 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 230 | - |
|
| 231 | - $debut = substr($texte, 0, $p); |
|
| 232 | - if ($p) { |
|
| 233 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 234 | - } |
|
| 235 | - $ligne += substr_count($debut, "\n"); |
|
| 236 | - $champ = new Champ(); |
|
| 237 | - $champ->ligne = $ligne; |
|
| 238 | - $ligne += substr_count($match[0], "\n"); |
|
| 239 | - $champ->nom_boucle = $match[2]; |
|
| 240 | - $champ->nom_champ = $match[3]; |
|
| 241 | - $champ->etoile = $match[5]; |
|
| 242 | - |
|
| 243 | - if ($suite and $suite[0] == '{') { |
|
| 244 | - phraser_arg($suite, '', [], $champ); |
|
| 245 | - // ce ltrim est une ereur de conception |
|
| 246 | - // mais on le conserve par souci de compatibilite |
|
| 247 | - $texte = ltrim($suite); |
|
| 248 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 249 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 250 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 226 | + while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 227 | + $p = strpos($texte, (string) $match[0]); |
|
| 228 | + // texte après la balise |
|
| 229 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 230 | + |
|
| 231 | + $debut = substr($texte, 0, $p); |
|
| 232 | + if ($p) { |
|
| 233 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 234 | + } |
|
| 235 | + $ligne += substr_count($debut, "\n"); |
|
| 236 | + $champ = new Champ(); |
|
| 237 | + $champ->ligne = $ligne; |
|
| 238 | + $ligne += substr_count($match[0], "\n"); |
|
| 239 | + $champ->nom_boucle = $match[2]; |
|
| 240 | + $champ->nom_champ = $match[3]; |
|
| 241 | + $champ->etoile = $match[5]; |
|
| 242 | + |
|
| 243 | + if ($suite and $suite[0] == '{') { |
|
| 244 | + phraser_arg($suite, '', [], $champ); |
|
| 245 | + // ce ltrim est une ereur de conception |
|
| 246 | + // mais on le conserve par souci de compatibilite |
|
| 247 | + $texte = ltrim($suite); |
|
| 248 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 249 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 250 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 251 | 251 | if ($n = (strlen($suite) - strlen($texte))) { |
| 252 | 252 | $champ->apres = array(new Texte); |
| 253 | 253 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 254 | 254 | } |
| 255 | 255 | */ |
| 256 | - } else { |
|
| 257 | - $texte = $suite; |
|
| 258 | - } |
|
| 259 | - phraser_vieux($champ); |
|
| 260 | - $result[] = $champ; |
|
| 261 | - } |
|
| 262 | - if ($texte !== '') { |
|
| 263 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return $result; |
|
| 256 | + } else { |
|
| 257 | + $texte = $suite; |
|
| 258 | + } |
|
| 259 | + phraser_vieux($champ); |
|
| 260 | + $result[] = $champ; |
|
| 261 | + } |
|
| 262 | + if ($texte !== '') { |
|
| 263 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return $result; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // Gestion des imbrications: |
@@ -272,15 +272,15 @@ discard block |
||
| 272 | 272 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 273 | 273 | |
| 274 | 274 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 275 | - if ($texte === '') { |
|
| 276 | - return $result; |
|
| 277 | - } |
|
| 278 | - $sep = '##'; |
|
| 279 | - while (strpos($texte, (string) $sep) !== false) { |
|
| 280 | - $sep .= '#'; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 275 | + if ($texte === '') { |
|
| 276 | + return $result; |
|
| 277 | + } |
|
| 278 | + $sep = '##'; |
|
| 279 | + while (strpos($texte, (string) $sep) !== false) { |
|
| 280 | + $sep .= '#'; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -299,275 +299,275 @@ discard block |
||
| 299 | 299 | * @return array |
| 300 | 300 | */ |
| 301 | 301 | function phraser_args(string $texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) { |
| 302 | - $length = strlen($texte); |
|
| 303 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | - $pos_debut++; |
|
| 305 | - } |
|
| 306 | - while (($pos_debut < $length) && !str_contains($fin, $texte[$pos_debut])) { |
|
| 307 | - // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 308 | - $st = substr($texte, $pos_debut); |
|
| 309 | - $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 310 | - $pos_debut = $length - strlen($st); |
|
| 311 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 312 | - $pos_debut++; |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - return $result; |
|
| 302 | + $length = strlen($texte); |
|
| 303 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | + $pos_debut++; |
|
| 305 | + } |
|
| 306 | + while (($pos_debut < $length) && !str_contains($fin, $texte[$pos_debut])) { |
|
| 307 | + // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 308 | + $st = substr($texte, $pos_debut); |
|
| 309 | + $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 310 | + $pos_debut = $length - strlen($st); |
|
| 311 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 312 | + $pos_debut++; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + return $result; |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 320 | - preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 321 | - $suite = ltrim($match[2]); |
|
| 322 | - $fonc = trim($match[1]); |
|
| 323 | - if ($fonc && $fonc[0] == '|') { |
|
| 324 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 325 | - } |
|
| 326 | - $res = [$fonc]; |
|
| 327 | - $err_f = ''; |
|
| 328 | - // cas du filtre sans argument ou du critere / |
|
| 329 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 330 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 331 | - if (!$match[1]) { |
|
| 332 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 333 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 334 | - $texte = ''; |
|
| 335 | - } else { |
|
| 336 | - $texte = $suite; |
|
| 337 | - } |
|
| 338 | - if ($err_f) { |
|
| 339 | - $pointeur_champ->param = false; |
|
| 340 | - } elseif ($fonc !== '') { |
|
| 341 | - $pointeur_champ->param[] = $res; |
|
| 342 | - } |
|
| 343 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 344 | - $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 345 | - |
|
| 346 | - return $result; |
|
| 347 | - } |
|
| 348 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 349 | - $collecte = []; |
|
| 350 | - while ($args && $args[0] != '}') { |
|
| 351 | - if ($args[0] == '"') { |
|
| 352 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 353 | - } elseif ($args[0] == "'") { |
|
| 354 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 355 | - } else { |
|
| 356 | - preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 357 | - if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 358 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 359 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 360 | - $champ = new Texte(); |
|
| 361 | - $champ->apres = $champ->avant = $args = ''; |
|
| 362 | - break; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - $arg = $regs[2]; |
|
| 366 | - if (trim($regs[1])) { |
|
| 367 | - $champ = new Texte(); |
|
| 368 | - $champ->texte = $arg; |
|
| 369 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 370 | - $result[] = $champ; |
|
| 371 | - $collecte[] = $champ; |
|
| 372 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 373 | - } else { |
|
| 374 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 375 | - // 0 est un aveu d'impuissance. A completer |
|
| 376 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 377 | - |
|
| 378 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 379 | - $collecte = array_merge($collecte, $arg); |
|
| 380 | - $result = array_merge($result, $arg); |
|
| 381 | - } else { |
|
| 382 | - $n = strpos($args, (string) $r[0]); |
|
| 383 | - $pred = substr($args, 0, $n); |
|
| 384 | - $par = ',}'; |
|
| 385 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 386 | - $pred = $m[1]; |
|
| 387 | - $par = ')'; |
|
| 388 | - } |
|
| 389 | - if ($pred) { |
|
| 390 | - $champ = new Texte(); |
|
| 391 | - $champ->texte = $pred; |
|
| 392 | - $champ->apres = $champ->avant = ''; |
|
| 393 | - $result[] = $champ; |
|
| 394 | - $collecte[] = $champ; |
|
| 395 | - } |
|
| 396 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 397 | - $champ = new Champ(); |
|
| 398 | - $champ->nom_boucle = $r[2]; |
|
| 399 | - $champ->nom_champ = $r[3]; |
|
| 400 | - $champ->etoile = $r[5]; |
|
| 401 | - $next = $r[6]; |
|
| 402 | - while ($next == '{') { |
|
| 403 | - phraser_arg($rec, $sep, [], $champ); |
|
| 404 | - $args = ltrim($rec); |
|
| 405 | - $next = $args[0] ?? ''; |
|
| 406 | - } |
|
| 407 | - while ($next == '|') { |
|
| 408 | - $pos_apres = 0; |
|
| 409 | - phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 410 | - $args = substr($rec, $pos_apres); |
|
| 411 | - $next = $args[0] ?? ''; |
|
| 412 | - } |
|
| 413 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 414 | - if ($champ->param === false) { |
|
| 415 | - $err_f = true; |
|
| 416 | - } else { |
|
| 417 | - phraser_vieux($champ); |
|
| 418 | - } |
|
| 419 | - if ($par == ')') { |
|
| 420 | - $args = substr($args, 1); |
|
| 421 | - } |
|
| 422 | - $collecte[] = $champ; |
|
| 423 | - $result[] = $champ; |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 427 | - $args = ltrim(substr($args, 1)); |
|
| 428 | - if ($collecte) { |
|
| 429 | - $res[] = $collecte; |
|
| 430 | - $collecte = []; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - if ($collecte) { |
|
| 435 | - $res[] = $collecte; |
|
| 436 | - $collecte = []; |
|
| 437 | - } |
|
| 438 | - $texte = substr($args, 1); |
|
| 439 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 440 | - // propager les erreurs, et ignorer les param vides |
|
| 441 | - if ($pointeur_champ->param !== false) { |
|
| 442 | - if ($err_f) { |
|
| 443 | - $pointeur_champ->param = false; |
|
| 444 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 445 | - $pointeur_champ->param[] = $res; |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 449 | - $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 450 | - |
|
| 451 | - return $result; |
|
| 320 | + preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 321 | + $suite = ltrim($match[2]); |
|
| 322 | + $fonc = trim($match[1]); |
|
| 323 | + if ($fonc && $fonc[0] == '|') { |
|
| 324 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 325 | + } |
|
| 326 | + $res = [$fonc]; |
|
| 327 | + $err_f = ''; |
|
| 328 | + // cas du filtre sans argument ou du critere / |
|
| 329 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 330 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 331 | + if (!$match[1]) { |
|
| 332 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 333 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 334 | + $texte = ''; |
|
| 335 | + } else { |
|
| 336 | + $texte = $suite; |
|
| 337 | + } |
|
| 338 | + if ($err_f) { |
|
| 339 | + $pointeur_champ->param = false; |
|
| 340 | + } elseif ($fonc !== '') { |
|
| 341 | + $pointeur_champ->param[] = $res; |
|
| 342 | + } |
|
| 343 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 344 | + $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 345 | + |
|
| 346 | + return $result; |
|
| 347 | + } |
|
| 348 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 349 | + $collecte = []; |
|
| 350 | + while ($args && $args[0] != '}') { |
|
| 351 | + if ($args[0] == '"') { |
|
| 352 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 353 | + } elseif ($args[0] == "'") { |
|
| 354 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 355 | + } else { |
|
| 356 | + preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 357 | + if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 358 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 359 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 360 | + $champ = new Texte(); |
|
| 361 | + $champ->apres = $champ->avant = $args = ''; |
|
| 362 | + break; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + $arg = $regs[2]; |
|
| 366 | + if (trim($regs[1])) { |
|
| 367 | + $champ = new Texte(); |
|
| 368 | + $champ->texte = $arg; |
|
| 369 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 370 | + $result[] = $champ; |
|
| 371 | + $collecte[] = $champ; |
|
| 372 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 373 | + } else { |
|
| 374 | + if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 375 | + // 0 est un aveu d'impuissance. A completer |
|
| 376 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 377 | + |
|
| 378 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 379 | + $collecte = array_merge($collecte, $arg); |
|
| 380 | + $result = array_merge($result, $arg); |
|
| 381 | + } else { |
|
| 382 | + $n = strpos($args, (string) $r[0]); |
|
| 383 | + $pred = substr($args, 0, $n); |
|
| 384 | + $par = ',}'; |
|
| 385 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 386 | + $pred = $m[1]; |
|
| 387 | + $par = ')'; |
|
| 388 | + } |
|
| 389 | + if ($pred) { |
|
| 390 | + $champ = new Texte(); |
|
| 391 | + $champ->texte = $pred; |
|
| 392 | + $champ->apres = $champ->avant = ''; |
|
| 393 | + $result[] = $champ; |
|
| 394 | + $collecte[] = $champ; |
|
| 395 | + } |
|
| 396 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 397 | + $champ = new Champ(); |
|
| 398 | + $champ->nom_boucle = $r[2]; |
|
| 399 | + $champ->nom_champ = $r[3]; |
|
| 400 | + $champ->etoile = $r[5]; |
|
| 401 | + $next = $r[6]; |
|
| 402 | + while ($next == '{') { |
|
| 403 | + phraser_arg($rec, $sep, [], $champ); |
|
| 404 | + $args = ltrim($rec); |
|
| 405 | + $next = $args[0] ?? ''; |
|
| 406 | + } |
|
| 407 | + while ($next == '|') { |
|
| 408 | + $pos_apres = 0; |
|
| 409 | + phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 410 | + $args = substr($rec, $pos_apres); |
|
| 411 | + $next = $args[0] ?? ''; |
|
| 412 | + } |
|
| 413 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 414 | + if ($champ->param === false) { |
|
| 415 | + $err_f = true; |
|
| 416 | + } else { |
|
| 417 | + phraser_vieux($champ); |
|
| 418 | + } |
|
| 419 | + if ($par == ')') { |
|
| 420 | + $args = substr($args, 1); |
|
| 421 | + } |
|
| 422 | + $collecte[] = $champ; |
|
| 423 | + $result[] = $champ; |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 427 | + $args = ltrim(substr($args, 1)); |
|
| 428 | + if ($collecte) { |
|
| 429 | + $res[] = $collecte; |
|
| 430 | + $collecte = []; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + if ($collecte) { |
|
| 435 | + $res[] = $collecte; |
|
| 436 | + $collecte = []; |
|
| 437 | + } |
|
| 438 | + $texte = substr($args, 1); |
|
| 439 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 440 | + // propager les erreurs, et ignorer les param vides |
|
| 441 | + if ($pointeur_champ->param !== false) { |
|
| 442 | + if ($err_f) { |
|
| 443 | + $pointeur_champ->param = false; |
|
| 444 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 445 | + $pointeur_champ->param[] = $res; |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 449 | + $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 450 | + |
|
| 451 | + return $result; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | |
| 455 | 455 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 456 | - $res = []; |
|
| 457 | - while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 458 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 459 | - break; |
|
| 460 | - } |
|
| 461 | - $debut = substr($texte, 0, $p); |
|
| 462 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 463 | - if ($p) { |
|
| 464 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 465 | - } |
|
| 466 | - $ligne += substr_count($debut, "\n"); |
|
| 467 | - $res[] = $nested[$m[1]]; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 456 | + $res = []; |
|
| 457 | + while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 458 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 459 | + break; |
|
| 460 | + } |
|
| 461 | + $debut = substr($texte, 0, $p); |
|
| 462 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 463 | + if ($p) { |
|
| 464 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 465 | + } |
|
| 466 | + $ligne += substr_count($debut, "\n"); |
|
| 467 | + $res[] = $nested[$m[1]]; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 474 | - $i = 0; // en fait count($result) |
|
| 475 | - $x = ''; |
|
| 476 | - |
|
| 477 | - while (true) { |
|
| 478 | - $j = $i; |
|
| 479 | - $n = $ligne; |
|
| 480 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | - $p = strpos($texte, (string) $match[0]); |
|
| 482 | - $debut = substr($texte, 0, $p); |
|
| 483 | - if ($p) { |
|
| 484 | - $result[$i] = $debut; |
|
| 485 | - $i++; |
|
| 486 | - } |
|
| 487 | - $nom = $match[4]; |
|
| 488 | - $champ = new Champ(); |
|
| 489 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | - $champ->nom_boucle = $match[3]; |
|
| 492 | - $champ->nom_champ = $nom; |
|
| 493 | - $champ->etoile = $match[6]; |
|
| 494 | - // phraser_args indiquera ou commence apres |
|
| 495 | - $pos_apres = 0; |
|
| 496 | - $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | - phraser_vieux($champ); |
|
| 498 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | - $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | - if (!empty($debut)) { |
|
| 501 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | - } |
|
| 503 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | - |
|
| 505 | - // reinjecter la boucle si c'en est une |
|
| 506 | - phraser_boucle_placeholder($champ); |
|
| 507 | - |
|
| 508 | - $result[$i] = $champ; |
|
| 509 | - $i++; |
|
| 510 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | - } |
|
| 512 | - if ($texte !== '') { |
|
| 513 | - $result[$i] = $texte; |
|
| 514 | - $i++; |
|
| 515 | - } |
|
| 516 | - $x = ''; |
|
| 517 | - |
|
| 518 | - while ($j < $i) { |
|
| 519 | - $z = $result[$j]; |
|
| 520 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | - if (is_object($z)) { |
|
| 522 | - $x .= "%$sep$j@"; |
|
| 523 | - } else { |
|
| 524 | - $x .= $z; |
|
| 525 | - } |
|
| 526 | - $j++; |
|
| 527 | - } |
|
| 528 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | - $texte = $x; |
|
| 530 | - } else { |
|
| 531 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | - } |
|
| 533 | - } |
|
| 474 | + $i = 0; // en fait count($result) |
|
| 475 | + $x = ''; |
|
| 476 | + |
|
| 477 | + while (true) { |
|
| 478 | + $j = $i; |
|
| 479 | + $n = $ligne; |
|
| 480 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | + $p = strpos($texte, (string) $match[0]); |
|
| 482 | + $debut = substr($texte, 0, $p); |
|
| 483 | + if ($p) { |
|
| 484 | + $result[$i] = $debut; |
|
| 485 | + $i++; |
|
| 486 | + } |
|
| 487 | + $nom = $match[4]; |
|
| 488 | + $champ = new Champ(); |
|
| 489 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | + $champ->nom_boucle = $match[3]; |
|
| 492 | + $champ->nom_champ = $nom; |
|
| 493 | + $champ->etoile = $match[6]; |
|
| 494 | + // phraser_args indiquera ou commence apres |
|
| 495 | + $pos_apres = 0; |
|
| 496 | + $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | + phraser_vieux($champ); |
|
| 498 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | + $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | + if (!empty($debut)) { |
|
| 501 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | + } |
|
| 503 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | + |
|
| 505 | + // reinjecter la boucle si c'en est une |
|
| 506 | + phraser_boucle_placeholder($champ); |
|
| 507 | + |
|
| 508 | + $result[$i] = $champ; |
|
| 509 | + $i++; |
|
| 510 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | + } |
|
| 512 | + if ($texte !== '') { |
|
| 513 | + $result[$i] = $texte; |
|
| 514 | + $i++; |
|
| 515 | + } |
|
| 516 | + $x = ''; |
|
| 517 | + |
|
| 518 | + while ($j < $i) { |
|
| 519 | + $z = $result[$j]; |
|
| 520 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | + if (is_object($z)) { |
|
| 522 | + $x .= "%$sep$j@"; |
|
| 523 | + } else { |
|
| 524 | + $x .= $z; |
|
| 525 | + } |
|
| 526 | + $j++; |
|
| 527 | + } |
|
| 528 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | + $texte = $x; |
|
| 530 | + } else { |
|
| 531 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | function phraser_vieux(&$champ) { |
| 537 | - $nom = $champ->nom_champ; |
|
| 538 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | - include_spip('public/normaliser'); |
|
| 541 | - } |
|
| 542 | - phraser_vieux_emb($champ); |
|
| 543 | - } elseif ($nom == 'EXPOSER') { |
|
| 544 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | - include_spip('public/normaliser'); |
|
| 546 | - } |
|
| 547 | - phraser_vieux_exposer($champ); |
|
| 548 | - } elseif ($champ->param) { |
|
| 549 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | - include_spip('public/normaliser'); |
|
| 552 | - } |
|
| 553 | - phraser_vieux_recherche($champ); |
|
| 554 | - } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | - include_spip('public/normaliser'); |
|
| 557 | - } |
|
| 558 | - phraser_vieux_logos($champ); |
|
| 559 | - } elseif ($nom == 'MODELE') { |
|
| 560 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | - include_spip('public/normaliser'); |
|
| 562 | - } |
|
| 563 | - phraser_vieux_modele($champ); |
|
| 564 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | - include_spip('public/normaliser'); |
|
| 567 | - } |
|
| 568 | - phraser_vieux_inclu($champ); |
|
| 569 | - } |
|
| 570 | - } |
|
| 537 | + $nom = $champ->nom_champ; |
|
| 538 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | + include_spip('public/normaliser'); |
|
| 541 | + } |
|
| 542 | + phraser_vieux_emb($champ); |
|
| 543 | + } elseif ($nom == 'EXPOSER') { |
|
| 544 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | + include_spip('public/normaliser'); |
|
| 546 | + } |
|
| 547 | + phraser_vieux_exposer($champ); |
|
| 548 | + } elseif ($champ->param) { |
|
| 549 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | + include_spip('public/normaliser'); |
|
| 552 | + } |
|
| 553 | + phraser_vieux_recherche($champ); |
|
| 554 | + } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | + include_spip('public/normaliser'); |
|
| 557 | + } |
|
| 558 | + phraser_vieux_logos($champ); |
|
| 559 | + } elseif ($nom == 'MODELE') { |
|
| 560 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | + include_spip('public/normaliser'); |
|
| 562 | + } |
|
| 563 | + phraser_vieux_modele($champ); |
|
| 564 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | + include_spip('public/normaliser'); |
|
| 567 | + } |
|
| 568 | + phraser_vieux_inclu($champ); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | |
@@ -595,200 +595,200 @@ discard block |
||
| 595 | 595 | **/ |
| 596 | 596 | function phraser_criteres($params, &$result) { |
| 597 | 597 | |
| 598 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | - $args = []; |
|
| 600 | - $type = $result->type_requete; |
|
| 601 | - $doublons = []; |
|
| 602 | - foreach ($params as $v) { |
|
| 603 | - $var = $v[1][0]; |
|
| 604 | - $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | - if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | - // plus d'un argument et pas le critere IN: |
|
| 607 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | - if ( |
|
| 609 | - $var->type != 'texte' |
|
| 610 | - or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | - ) { |
|
| 612 | - $op = ','; |
|
| 613 | - $not = false; |
|
| 614 | - $cond = false; |
|
| 615 | - } else { |
|
| 616 | - // Le debut du premier argument est l'operateur |
|
| 617 | - preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | - $op = $m[2]; |
|
| 619 | - $not = (bool) $m[1]; |
|
| 620 | - $cond = $m[3]; |
|
| 621 | - // virer le premier argument, |
|
| 622 | - // et mettre son reliquat eventuel |
|
| 623 | - // Recopier pour ne pas alterer le texte source |
|
| 624 | - // utile au debusqueur |
|
| 625 | - if ($m[4]) { |
|
| 626 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | - $c = null; |
|
| 629 | - eval('$c = ' . $m[4] . ';'); |
|
| 630 | - if (isset($c)) { |
|
| 631 | - $m[4] = $c; |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - $texte = new Texte(); |
|
| 635 | - $texte->texte = $m[4]; |
|
| 636 | - $v[1][0] = $texte; |
|
| 637 | - } else { |
|
| 638 | - array_shift($v[1]); |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - array_shift($v); // $v[O] est vide |
|
| 642 | - $crit = new Critere(); |
|
| 643 | - $crit->op = $op; |
|
| 644 | - $crit->not = $not; |
|
| 645 | - $crit->cond = $cond; |
|
| 646 | - $crit->exclus = ''; |
|
| 647 | - $crit->param = $v; |
|
| 648 | - $args[] = $crit; |
|
| 649 | - } else { |
|
| 650 | - if ($var->type != 'texte') { |
|
| 651 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | - // erreur ou critere infixe "/" |
|
| 653 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | - $err_ci = [ |
|
| 655 | - 'zbug_critere_inconnu', |
|
| 656 | - ['critere' => $var->nom_champ] |
|
| 657 | - ]; |
|
| 658 | - erreur_squelette($err_ci, $result); |
|
| 659 | - } else { |
|
| 660 | - $crit = new Critere(); |
|
| 661 | - $crit->op = '/'; |
|
| 662 | - $crit->not = false; |
|
| 663 | - $crit->exclus = ''; |
|
| 664 | - $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | - $args[] = $crit; |
|
| 666 | - } |
|
| 667 | - } else { |
|
| 668 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | - // les separateurs |
|
| 670 | - if ($var->apres) { |
|
| 671 | - $result->separateur[] = $param; |
|
| 672 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | - $result->modificateur['tout'] = true; |
|
| 674 | - } elseif ($param == 'plat') { |
|
| 675 | - $result->modificateur['plat'] = true; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | - // ceux-ci pour avoir la rubrique mere... |
|
| 681 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | - // traités normalement. |
|
| 683 | - elseif ( |
|
| 684 | - strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | - and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | - ) { |
|
| 688 | - $result->modificateur['tout'] = true; |
|
| 689 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | - // rien a faire sur {id_rubrique} tout seul |
|
| 691 | - } else { |
|
| 692 | - // pas d'emplacement statique, faut un dynamique |
|
| 693 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | - // cette variable sera inseree dans le code |
|
| 696 | - // et son nom sert d'indicateur des maintenant |
|
| 697 | - $result->doublons = '$doublons_index'; |
|
| 698 | - if ($param == 'unique') { |
|
| 699 | - $param = 'doublons'; |
|
| 700 | - } |
|
| 701 | - } elseif ($param == 'recherche') { |
|
| 702 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | - $result->hash = ' '; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | - } elseif ( |
|
| 709 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | - ) { |
|
| 712 | - $a2 = trim($m[8]); |
|
| 713 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | - $a2 = substr($a2, 1, -1); |
|
| 715 | - } |
|
| 716 | - $crit = phraser_critere_infixe( |
|
| 717 | - $m[2], |
|
| 718 | - $a2, |
|
| 719 | - $v, |
|
| 720 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | - $m[6], |
|
| 722 | - $m[5] |
|
| 723 | - ); |
|
| 724 | - $crit->exclus = $m[1]; |
|
| 725 | - } elseif ( |
|
| 726 | - preg_match('/^([!]?)\s*(' . |
|
| 727 | - CHAMP_SQL_PLUS_FONC . |
|
| 728 | - ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | - ) { |
|
| 730 | - // contient aussi les comparaisons implicites ! |
|
| 731 | - // Comme ci-dessus: |
|
| 732 | - // le premier arg contient l'operateur |
|
| 733 | - array_shift($v); |
|
| 734 | - if ($m[6]) { |
|
| 735 | - $v[0][0] = new Texte(); |
|
| 736 | - $v[0][0]->texte = $m[6]; |
|
| 737 | - } else { |
|
| 738 | - array_shift($v[0]); |
|
| 739 | - if (!$v[0]) { |
|
| 740 | - array_shift($v); |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - $crit = new Critere(); |
|
| 744 | - $crit->op = $m[2]; |
|
| 745 | - $crit->param = $v; |
|
| 746 | - $crit->not = (bool) $m[1]; |
|
| 747 | - $crit->cond = $m[5]; |
|
| 748 | - } else { |
|
| 749 | - $err_ci = [ |
|
| 750 | - 'zbug_critere_inconnu', |
|
| 751 | - ['critere' => $param] |
|
| 752 | - ]; |
|
| 753 | - erreur_squelette($err_ci, $result); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | - $args[] = $crit; |
|
| 758 | - } else { |
|
| 759 | - $doublons[] = $crit; |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - // les doublons non nies doivent etre le dernier critere |
|
| 767 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | - // cf critere_doublon |
|
| 769 | - if ($doublons) { |
|
| 770 | - $args = [...$args, ...$doublons]; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | - if (!$err_ci) { |
|
| 775 | - $result->criteres = $args; |
|
| 776 | - } |
|
| 598 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | + $args = []; |
|
| 600 | + $type = $result->type_requete; |
|
| 601 | + $doublons = []; |
|
| 602 | + foreach ($params as $v) { |
|
| 603 | + $var = $v[1][0]; |
|
| 604 | + $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | + if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | + // plus d'un argument et pas le critere IN: |
|
| 607 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | + if ( |
|
| 609 | + $var->type != 'texte' |
|
| 610 | + or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | + ) { |
|
| 612 | + $op = ','; |
|
| 613 | + $not = false; |
|
| 614 | + $cond = false; |
|
| 615 | + } else { |
|
| 616 | + // Le debut du premier argument est l'operateur |
|
| 617 | + preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | + $op = $m[2]; |
|
| 619 | + $not = (bool) $m[1]; |
|
| 620 | + $cond = $m[3]; |
|
| 621 | + // virer le premier argument, |
|
| 622 | + // et mettre son reliquat eventuel |
|
| 623 | + // Recopier pour ne pas alterer le texte source |
|
| 624 | + // utile au debusqueur |
|
| 625 | + if ($m[4]) { |
|
| 626 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | + $c = null; |
|
| 629 | + eval('$c = ' . $m[4] . ';'); |
|
| 630 | + if (isset($c)) { |
|
| 631 | + $m[4] = $c; |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + $texte = new Texte(); |
|
| 635 | + $texte->texte = $m[4]; |
|
| 636 | + $v[1][0] = $texte; |
|
| 637 | + } else { |
|
| 638 | + array_shift($v[1]); |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + array_shift($v); // $v[O] est vide |
|
| 642 | + $crit = new Critere(); |
|
| 643 | + $crit->op = $op; |
|
| 644 | + $crit->not = $not; |
|
| 645 | + $crit->cond = $cond; |
|
| 646 | + $crit->exclus = ''; |
|
| 647 | + $crit->param = $v; |
|
| 648 | + $args[] = $crit; |
|
| 649 | + } else { |
|
| 650 | + if ($var->type != 'texte') { |
|
| 651 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | + // erreur ou critere infixe "/" |
|
| 653 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | + $err_ci = [ |
|
| 655 | + 'zbug_critere_inconnu', |
|
| 656 | + ['critere' => $var->nom_champ] |
|
| 657 | + ]; |
|
| 658 | + erreur_squelette($err_ci, $result); |
|
| 659 | + } else { |
|
| 660 | + $crit = new Critere(); |
|
| 661 | + $crit->op = '/'; |
|
| 662 | + $crit->not = false; |
|
| 663 | + $crit->exclus = ''; |
|
| 664 | + $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | + $args[] = $crit; |
|
| 666 | + } |
|
| 667 | + } else { |
|
| 668 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | + // les separateurs |
|
| 670 | + if ($var->apres) { |
|
| 671 | + $result->separateur[] = $param; |
|
| 672 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | + $result->modificateur['tout'] = true; |
|
| 674 | + } elseif ($param == 'plat') { |
|
| 675 | + $result->modificateur['plat'] = true; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | + // ceux-ci pour avoir la rubrique mere... |
|
| 681 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | + // traités normalement. |
|
| 683 | + elseif ( |
|
| 684 | + strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | + and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | + ) { |
|
| 688 | + $result->modificateur['tout'] = true; |
|
| 689 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | + // rien a faire sur {id_rubrique} tout seul |
|
| 691 | + } else { |
|
| 692 | + // pas d'emplacement statique, faut un dynamique |
|
| 693 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | + // cette variable sera inseree dans le code |
|
| 696 | + // et son nom sert d'indicateur des maintenant |
|
| 697 | + $result->doublons = '$doublons_index'; |
|
| 698 | + if ($param == 'unique') { |
|
| 699 | + $param = 'doublons'; |
|
| 700 | + } |
|
| 701 | + } elseif ($param == 'recherche') { |
|
| 702 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | + $result->hash = ' '; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | + } elseif ( |
|
| 709 | + preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | + ) { |
|
| 712 | + $a2 = trim($m[8]); |
|
| 713 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | + $a2 = substr($a2, 1, -1); |
|
| 715 | + } |
|
| 716 | + $crit = phraser_critere_infixe( |
|
| 717 | + $m[2], |
|
| 718 | + $a2, |
|
| 719 | + $v, |
|
| 720 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | + $m[6], |
|
| 722 | + $m[5] |
|
| 723 | + ); |
|
| 724 | + $crit->exclus = $m[1]; |
|
| 725 | + } elseif ( |
|
| 726 | + preg_match('/^([!]?)\s*(' . |
|
| 727 | + CHAMP_SQL_PLUS_FONC . |
|
| 728 | + ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | + ) { |
|
| 730 | + // contient aussi les comparaisons implicites ! |
|
| 731 | + // Comme ci-dessus: |
|
| 732 | + // le premier arg contient l'operateur |
|
| 733 | + array_shift($v); |
|
| 734 | + if ($m[6]) { |
|
| 735 | + $v[0][0] = new Texte(); |
|
| 736 | + $v[0][0]->texte = $m[6]; |
|
| 737 | + } else { |
|
| 738 | + array_shift($v[0]); |
|
| 739 | + if (!$v[0]) { |
|
| 740 | + array_shift($v); |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + $crit = new Critere(); |
|
| 744 | + $crit->op = $m[2]; |
|
| 745 | + $crit->param = $v; |
|
| 746 | + $crit->not = (bool) $m[1]; |
|
| 747 | + $crit->cond = $m[5]; |
|
| 748 | + } else { |
|
| 749 | + $err_ci = [ |
|
| 750 | + 'zbug_critere_inconnu', |
|
| 751 | + ['critere' => $param] |
|
| 752 | + ]; |
|
| 753 | + erreur_squelette($err_ci, $result); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | + $args[] = $crit; |
|
| 758 | + } else { |
|
| 759 | + $doublons[] = $crit; |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + // les doublons non nies doivent etre le dernier critere |
|
| 767 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | + // cf critere_doublon |
|
| 769 | + if ($doublons) { |
|
| 770 | + $args = [...$args, ...$doublons]; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | + if (!$err_ci) { |
|
| 775 | + $result->criteres = $args; |
|
| 776 | + } |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 780 | - $args[0] = new Texte(); |
|
| 781 | - $args[0]->texte = $arg1; |
|
| 782 | - $args[0] = [$args[0]]; |
|
| 783 | - $args[1][0] = new Texte(); |
|
| 784 | - $args[1][0]->texte = $arg2; |
|
| 785 | - $crit = new Critere(); |
|
| 786 | - $crit->op = $op; |
|
| 787 | - $crit->not = $not; |
|
| 788 | - $crit->cond = $cond; |
|
| 789 | - $crit->param = $args; |
|
| 790 | - |
|
| 791 | - return $crit; |
|
| 780 | + $args[0] = new Texte(); |
|
| 781 | + $args[0]->texte = $arg1; |
|
| 782 | + $args[0] = [$args[0]]; |
|
| 783 | + $args[1][0] = new Texte(); |
|
| 784 | + $args[1][0]->texte = $arg2; |
|
| 785 | + $crit = new Critere(); |
|
| 786 | + $crit->op = $op; |
|
| 787 | + $crit->not = $not; |
|
| 788 | + $crit->cond = $cond; |
|
| 789 | + $crit->param = $args; |
|
| 790 | + |
|
| 791 | + return $crit; |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | /** |
@@ -799,12 +799,12 @@ discard block |
||
| 799 | 799 | * @return int |
| 800 | 800 | */ |
| 801 | 801 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 802 | - if (is_null($fin)) { |
|
| 803 | - return substr_count($texte, "\n", $debut); |
|
| 804 | - } |
|
| 805 | - else { |
|
| 806 | - return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 807 | - } |
|
| 802 | + if (is_null($fin)) { |
|
| 803 | + return substr_count($texte, "\n", $debut); |
|
| 804 | + } |
|
| 805 | + else { |
|
| 806 | + return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 807 | + } |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | |
@@ -820,87 +820,87 @@ discard block |
||
| 820 | 820 | * @return array|null |
| 821 | 821 | */ |
| 822 | 822 | function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) { |
| 823 | - $premiere_boucle = null; |
|
| 824 | - $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 825 | - |
|
| 826 | - $current_pos = $pos_debut_texte; |
|
| 827 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 828 | - $current_pos = $pos_boucle + 1; |
|
| 829 | - $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 830 | - |
|
| 831 | - $id_boucle = ''; |
|
| 832 | - if ($pos_parent !== false) { |
|
| 833 | - $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 834 | - } |
|
| 835 | - if ( |
|
| 836 | - $pos_parent === false |
|
| 837 | - or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 838 | - ) { |
|
| 839 | - $result = new Boucle(); |
|
| 840 | - $result->id_parent = $id_parent; |
|
| 841 | - $result->descr = $descr; |
|
| 842 | - |
|
| 843 | - // un id_boucle pour l'affichage de l'erreur |
|
| 844 | - if (!strlen($id_boucle)) { |
|
| 845 | - $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 846 | - } |
|
| 847 | - $result->id_boucle = $id_boucle; |
|
| 848 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 849 | - erreur_squelette($err_b, $result); |
|
| 850 | - |
|
| 851 | - continue; |
|
| 852 | - } |
|
| 853 | - else { |
|
| 854 | - $boucle = [ |
|
| 855 | - 'id_boucle' => $id_boucle, |
|
| 856 | - 'id_boucle_err' => $id_boucle, |
|
| 857 | - 'debut_boucle' => $pos_boucle, |
|
| 858 | - 'pos_boucle' => $pos_boucle, |
|
| 859 | - 'pos_parent' => $pos_parent, |
|
| 860 | - 'pos_precond' => false, |
|
| 861 | - 'pos_precond_inside' => false, |
|
| 862 | - 'pos_preaff' => false, |
|
| 863 | - 'pos_preaff_inside' => false, |
|
| 864 | - ]; |
|
| 865 | - |
|
| 866 | - // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 867 | - if (!strlen($id_boucle)) { |
|
| 868 | - $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 869 | - } |
|
| 870 | - |
|
| 871 | - // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 872 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 873 | - $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 874 | - if ( |
|
| 875 | - $pos_precond !== false |
|
| 876 | - and $pos_precond < $boucle['debut_boucle'] |
|
| 877 | - ) { |
|
| 878 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 879 | - $boucle['pos_precond'] = $pos_precond; |
|
| 880 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 884 | - $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 885 | - if ( |
|
| 886 | - $pos_preaff !== false |
|
| 887 | - and $pos_preaff < $boucle['debut_boucle'] |
|
| 888 | - ) { |
|
| 889 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 890 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 891 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 892 | - } |
|
| 893 | - if (!strlen($id_boucle)) { |
|
| 894 | - $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 898 | - $premiere_boucle = $boucle; |
|
| 899 | - } |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - return $premiere_boucle; |
|
| 823 | + $premiere_boucle = null; |
|
| 824 | + $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 825 | + |
|
| 826 | + $current_pos = $pos_debut_texte; |
|
| 827 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 828 | + $current_pos = $pos_boucle + 1; |
|
| 829 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 830 | + |
|
| 831 | + $id_boucle = ''; |
|
| 832 | + if ($pos_parent !== false) { |
|
| 833 | + $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 834 | + } |
|
| 835 | + if ( |
|
| 836 | + $pos_parent === false |
|
| 837 | + or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 838 | + ) { |
|
| 839 | + $result = new Boucle(); |
|
| 840 | + $result->id_parent = $id_parent; |
|
| 841 | + $result->descr = $descr; |
|
| 842 | + |
|
| 843 | + // un id_boucle pour l'affichage de l'erreur |
|
| 844 | + if (!strlen($id_boucle)) { |
|
| 845 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 846 | + } |
|
| 847 | + $result->id_boucle = $id_boucle; |
|
| 848 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 849 | + erreur_squelette($err_b, $result); |
|
| 850 | + |
|
| 851 | + continue; |
|
| 852 | + } |
|
| 853 | + else { |
|
| 854 | + $boucle = [ |
|
| 855 | + 'id_boucle' => $id_boucle, |
|
| 856 | + 'id_boucle_err' => $id_boucle, |
|
| 857 | + 'debut_boucle' => $pos_boucle, |
|
| 858 | + 'pos_boucle' => $pos_boucle, |
|
| 859 | + 'pos_parent' => $pos_parent, |
|
| 860 | + 'pos_precond' => false, |
|
| 861 | + 'pos_precond_inside' => false, |
|
| 862 | + 'pos_preaff' => false, |
|
| 863 | + 'pos_preaff_inside' => false, |
|
| 864 | + ]; |
|
| 865 | + |
|
| 866 | + // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 867 | + if (!strlen($id_boucle)) { |
|
| 868 | + $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 869 | + } |
|
| 870 | + |
|
| 871 | + // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 872 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 873 | + $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 874 | + if ( |
|
| 875 | + $pos_precond !== false |
|
| 876 | + and $pos_precond < $boucle['debut_boucle'] |
|
| 877 | + ) { |
|
| 878 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 879 | + $boucle['pos_precond'] = $pos_precond; |
|
| 880 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 884 | + $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 885 | + if ( |
|
| 886 | + $pos_preaff !== false |
|
| 887 | + and $pos_preaff < $boucle['debut_boucle'] |
|
| 888 | + ) { |
|
| 889 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 890 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 891 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 892 | + } |
|
| 893 | + if (!strlen($id_boucle)) { |
|
| 894 | + $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 898 | + $premiere_boucle = $boucle; |
|
| 899 | + } |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + return $premiere_boucle; |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | /** |
@@ -915,68 +915,68 @@ discard block |
||
| 915 | 915 | * @return mixed |
| 916 | 916 | */ |
| 917 | 917 | function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) { |
| 918 | - $id_boucle = $boucle['id_boucle']; |
|
| 919 | - $pos_courante = $pos_debut_texte; |
|
| 920 | - |
|
| 921 | - $boucle['pos_postcond'] = false; |
|
| 922 | - $boucle['pos_postcond_inside'] = false; |
|
| 923 | - $boucle['pos_altern'] = false; |
|
| 924 | - $boucle['pos_altern_inside'] = false; |
|
| 925 | - $boucle['pos_postaff'] = false; |
|
| 926 | - $boucle['pos_postaff_inside'] = false; |
|
| 927 | - |
|
| 928 | - $pos_anonyme_next = null; |
|
| 929 | - // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 930 | - if (!strlen($id_boucle)) { |
|
| 931 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - // |
|
| 935 | - // 1. Recuperer la partie conditionnelle apres |
|
| 936 | - // |
|
| 937 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 938 | - $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 939 | - if ( |
|
| 940 | - $pos_apres !== false |
|
| 941 | - and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 942 | - ) { |
|
| 943 | - $boucle['pos_postcond'] = $pos_apres; |
|
| 944 | - $pos_apres += strlen($apres_boucle); |
|
| 945 | - $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 946 | - $pos_courante = $pos_apres ; |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - // |
|
| 950 | - // 2. Récuperer la partie alternative apres |
|
| 951 | - // |
|
| 952 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 953 | - $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 954 | - if ( |
|
| 955 | - $pos_altern !== false |
|
| 956 | - and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 957 | - ) { |
|
| 958 | - $boucle['pos_altern'] = $pos_altern; |
|
| 959 | - $pos_altern += strlen($altern_boucle); |
|
| 960 | - $boucle['pos_altern_inside'] = $pos_altern; |
|
| 961 | - $pos_courante = $pos_altern; |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - // |
|
| 965 | - // 3. Recuperer la partie footer non alternative |
|
| 966 | - // |
|
| 967 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 968 | - $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 969 | - if ( |
|
| 970 | - $pos_postaff !== false |
|
| 971 | - and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 972 | - ) { |
|
| 973 | - $boucle['pos_postaff'] = $pos_postaff; |
|
| 974 | - $pos_postaff += strlen($postaff_boucle); |
|
| 975 | - $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 976 | - $pos_courante = $pos_postaff ; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - return $boucle; |
|
| 918 | + $id_boucle = $boucle['id_boucle']; |
|
| 919 | + $pos_courante = $pos_debut_texte; |
|
| 920 | + |
|
| 921 | + $boucle['pos_postcond'] = false; |
|
| 922 | + $boucle['pos_postcond_inside'] = false; |
|
| 923 | + $boucle['pos_altern'] = false; |
|
| 924 | + $boucle['pos_altern_inside'] = false; |
|
| 925 | + $boucle['pos_postaff'] = false; |
|
| 926 | + $boucle['pos_postaff_inside'] = false; |
|
| 927 | + |
|
| 928 | + $pos_anonyme_next = null; |
|
| 929 | + // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 930 | + if (!strlen($id_boucle)) { |
|
| 931 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + // |
|
| 935 | + // 1. Recuperer la partie conditionnelle apres |
|
| 936 | + // |
|
| 937 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 938 | + $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 939 | + if ( |
|
| 940 | + $pos_apres !== false |
|
| 941 | + and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 942 | + ) { |
|
| 943 | + $boucle['pos_postcond'] = $pos_apres; |
|
| 944 | + $pos_apres += strlen($apres_boucle); |
|
| 945 | + $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 946 | + $pos_courante = $pos_apres ; |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + // |
|
| 950 | + // 2. Récuperer la partie alternative apres |
|
| 951 | + // |
|
| 952 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 953 | + $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 954 | + if ( |
|
| 955 | + $pos_altern !== false |
|
| 956 | + and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 957 | + ) { |
|
| 958 | + $boucle['pos_altern'] = $pos_altern; |
|
| 959 | + $pos_altern += strlen($altern_boucle); |
|
| 960 | + $boucle['pos_altern_inside'] = $pos_altern; |
|
| 961 | + $pos_courante = $pos_altern; |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + // |
|
| 965 | + // 3. Recuperer la partie footer non alternative |
|
| 966 | + // |
|
| 967 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 968 | + $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 969 | + if ( |
|
| 970 | + $pos_postaff !== false |
|
| 971 | + and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 972 | + ) { |
|
| 973 | + $boucle['pos_postaff'] = $pos_postaff; |
|
| 974 | + $pos_postaff += strlen($postaff_boucle); |
|
| 975 | + $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 976 | + $pos_courante = $pos_postaff ; |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + return $boucle; |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | |
@@ -986,21 +986,21 @@ discard block |
||
| 986 | 986 | * @param null|object $boucle |
| 987 | 987 | */ |
| 988 | 988 | function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) { |
| 989 | - static $boucles_connues = []; |
|
| 990 | - // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 991 | - if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 992 | - $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 993 | - } |
|
| 994 | - else { |
|
| 995 | - if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 996 | - $placeholder = $champ->nom_champ; |
|
| 997 | - $id = reset($champ->param[0][1]); |
|
| 998 | - $id = $id->texte; |
|
| 999 | - if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1000 | - $champ = $boucles_connues[$placeholder][$id]; |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 989 | + static $boucles_connues = []; |
|
| 990 | + // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 991 | + if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 992 | + $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 993 | + } |
|
| 994 | + else { |
|
| 995 | + if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 996 | + $placeholder = $champ->nom_champ; |
|
| 997 | + $id = reset($champ->param[0][1]); |
|
| 998 | + $id = $id->texte; |
|
| 999 | + if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1000 | + $champ = $boucles_connues[$placeholder][$id]; |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | |
@@ -1013,274 +1013,274 @@ discard block |
||
| 1013 | 1013 | * @return string |
| 1014 | 1014 | */ |
| 1015 | 1015 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1016 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1017 | - //memoriser la boucle a reinjecter |
|
| 1018 | - $id_boucle = "$id_boucle"; |
|
| 1019 | - phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1020 | - return $placeholder; |
|
| 1016 | + $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1017 | + //memoriser la boucle a reinjecter |
|
| 1018 | + $id_boucle = "$id_boucle"; |
|
| 1019 | + phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1020 | + return $placeholder; |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) { |
| 1024 | 1024 | |
| 1025 | - $all_res = []; |
|
| 1026 | - // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1027 | - if (is_null($boucle_placeholder)) { |
|
| 1028 | - do { |
|
| 1029 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1030 | - } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - $ligne_debut_initial = $ligne_debut_texte; |
|
| 1034 | - $pos_debut_texte = 0; |
|
| 1035 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1036 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1037 | - $result = new Boucle(); |
|
| 1038 | - $result->id_parent = $id_parent; |
|
| 1039 | - $result->descr = $descr; |
|
| 1040 | - |
|
| 1041 | - $pos_courante = $boucle['pos_boucle']; |
|
| 1042 | - $pos_parent = $boucle['pos_parent']; |
|
| 1043 | - $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1044 | - |
|
| 1045 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1046 | - |
|
| 1047 | - // boucle anonyme ? |
|
| 1048 | - if (!strlen($id_boucle)) { |
|
| 1049 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - $pos_debut_boucle = $pos_courante; |
|
| 1053 | - |
|
| 1054 | - $pos_milieu = $pos_parent; |
|
| 1055 | - |
|
| 1056 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1057 | - if ($boucle['pos_precond'] !== false) { |
|
| 1058 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1059 | - |
|
| 1060 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 1061 | - $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1062 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1066 | - if ($boucle['pos_preaff'] !== false) { |
|
| 1067 | - $end_preaff = $pos_debut_boucle; |
|
| 1068 | - |
|
| 1069 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1070 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1071 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - $result->id_boucle = $id_boucle; |
|
| 1075 | - |
|
| 1076 | - if ( |
|
| 1077 | - !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1078 | - or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1079 | - or $pos_match > $pos_milieu |
|
| 1080 | - ) { |
|
| 1081 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1082 | - erreur_squelette($err_b, $result); |
|
| 1083 | - |
|
| 1084 | - $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1085 | - $pos_debut_texte = $pos_courante + 1; |
|
| 1086 | - continue; |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - $result->type_requete = $match[0]; |
|
| 1090 | - $pos_milieu += strlen($match[0]); |
|
| 1091 | - $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1092 | - |
|
| 1093 | - $type = $match[1]; |
|
| 1094 | - $jointures = trim($match[2]); |
|
| 1095 | - $table_optionnelle = ($match[3]); |
|
| 1096 | - if ($jointures) { |
|
| 1097 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1098 | - // ou elles seront completees des jointures declarees |
|
| 1099 | - $result->jointures_explicites = $jointures; |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - if ($table_optionnelle) { |
|
| 1103 | - $result->table_optionnelle = $type; |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1107 | - // Resultat mis dans result->param |
|
| 1108 | - $pos_fin_criteres = $pos_milieu; |
|
| 1109 | - phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1110 | - |
|
| 1111 | - // En 2e passe result->criteres contiendra un tableau |
|
| 1112 | - // pour l'instant on met le source (chaine) : |
|
| 1113 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1114 | - $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1115 | - $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1116 | - $pos_milieu = $pos_fin_criteres; |
|
| 1117 | - |
|
| 1118 | - // |
|
| 1119 | - // Recuperer la fin : |
|
| 1120 | - // |
|
| 1121 | - if ($texte[$pos_milieu] === '/') { |
|
| 1122 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 1123 | - $pos_courante += 2; |
|
| 1124 | - $result->milieu = ''; |
|
| 1125 | - } else { |
|
| 1126 | - $pos_milieu += 1; |
|
| 1127 | - |
|
| 1128 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1129 | - $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1130 | - if ($pos_fin === false) { |
|
| 1131 | - $err_b = [ |
|
| 1132 | - 'zbug_erreur_boucle_fermant', |
|
| 1133 | - ['id' => $id_boucle] |
|
| 1134 | - ]; |
|
| 1135 | - erreur_squelette($err_b, $result); |
|
| 1136 | - $pos_courante += strlen($fin_boucle); |
|
| 1137 | - } |
|
| 1138 | - else { |
|
| 1139 | - // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1140 | - // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1141 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1142 | - $search_from = $pos_milieu; |
|
| 1143 | - $nb_open = 1; |
|
| 1144 | - $nb_close = 1; |
|
| 1145 | - $maxiter = 0; |
|
| 1146 | - do { |
|
| 1147 | - while ( |
|
| 1148 | - $nb_close < $nb_open |
|
| 1149 | - and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1150 | - ) { |
|
| 1151 | - $nb_close++; |
|
| 1152 | - $pos_fin = $p; |
|
| 1153 | - } |
|
| 1154 | - // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1155 | - if ($nb_close < $nb_open) { |
|
| 1156 | - break; |
|
| 1157 | - } |
|
| 1158 | - while ( |
|
| 1159 | - $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1160 | - and $p < $pos_fin |
|
| 1161 | - ) { |
|
| 1162 | - $nb_open++; |
|
| 1163 | - $search_from = $p + 1; |
|
| 1164 | - } |
|
| 1165 | - } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1166 | - |
|
| 1167 | - $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1168 | - } |
|
| 1169 | - $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1173 | - $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1174 | - |
|
| 1175 | - // |
|
| 1176 | - // 1. Partie conditionnelle apres ? |
|
| 1177 | - // |
|
| 1178 | - if ($boucle['pos_postcond']) { |
|
| 1179 | - $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1180 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1181 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - |
|
| 1185 | - // |
|
| 1186 | - // 2. Partie alternative apres ? |
|
| 1187 | - // |
|
| 1188 | - $ligne_altern = $ligne_suite; |
|
| 1189 | - if ($boucle['pos_altern']) { |
|
| 1190 | - $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1191 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1192 | - $pos_courante = $boucle['pos_altern_inside']; |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - // |
|
| 1196 | - // 3. Partie footer non alternative ? |
|
| 1197 | - // |
|
| 1198 | - $ligne_postaff = $ligne_suite; |
|
| 1199 | - if ($boucle['pos_postaff']) { |
|
| 1200 | - $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1201 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1202 | - $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - $result->ligne = $ligne_preaff; |
|
| 1206 | - |
|
| 1207 | - if ($p = strpos($type, ':')) { |
|
| 1208 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1209 | - $type = substr($type, $p + 1); |
|
| 1210 | - } |
|
| 1211 | - $soustype = strtolower($type); |
|
| 1212 | - |
|
| 1213 | - if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1214 | - $soustype = $type; |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - $result->type_requete = $soustype; |
|
| 1218 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1219 | - if (!is_array($result->param)) { |
|
| 1220 | - $err_b = true; |
|
| 1221 | - } else { |
|
| 1222 | - phraser_criteres($result->param, $result); |
|
| 1223 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1224 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1225 | - $args = $result->param; |
|
| 1226 | - array_unshift( |
|
| 1227 | - $args, |
|
| 1228 | - substr($type, strlen(TYPE_RECURSIF)) |
|
| 1229 | - ); |
|
| 1230 | - $result->param = $args; |
|
| 1231 | - } |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1235 | - $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1236 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1237 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1238 | - // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1239 | - if (empty($boucles[$id_boucle])) { |
|
| 1240 | - $boucles[$id_boucle] = null; |
|
| 1241 | - } |
|
| 1242 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1243 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1244 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1245 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1246 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1247 | - |
|
| 1248 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1249 | - if ($err_b) { |
|
| 1250 | - $result->type_requete = false; |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - // Verifier qu'il n'y a pas double definition |
|
| 1254 | - // apres analyse des sous-parties (pas avant). |
|
| 1255 | - if (!empty($boucles[$id_boucle])) { |
|
| 1256 | - if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1257 | - $err_b_d = [ |
|
| 1258 | - 'zbug_erreur_boucle_double', |
|
| 1259 | - ['id' => $id_boucle] |
|
| 1260 | - ]; |
|
| 1261 | - erreur_squelette($err_b_d, $result); |
|
| 1262 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1263 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1264 | - } |
|
| 1265 | - } else { |
|
| 1266 | - $boucles[$id_boucle] = $result; |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1270 | - $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1271 | - $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1272 | - $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1273 | - $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1274 | - |
|
| 1275 | - // phraser la partie avant le debut de la boucle |
|
| 1276 | - #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1277 | - #$all_res[] = &$boucles[$id_boucle]; |
|
| 1278 | - |
|
| 1279 | - $ligne_debut_texte = $ligne_suite; |
|
| 1280 | - $pos_debut_texte = $pos_courante; |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1284 | - |
|
| 1285 | - return $all_res; |
|
| 1025 | + $all_res = []; |
|
| 1026 | + // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1027 | + if (is_null($boucle_placeholder)) { |
|
| 1028 | + do { |
|
| 1029 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1030 | + } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + $ligne_debut_initial = $ligne_debut_texte; |
|
| 1034 | + $pos_debut_texte = 0; |
|
| 1035 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1036 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1037 | + $result = new Boucle(); |
|
| 1038 | + $result->id_parent = $id_parent; |
|
| 1039 | + $result->descr = $descr; |
|
| 1040 | + |
|
| 1041 | + $pos_courante = $boucle['pos_boucle']; |
|
| 1042 | + $pos_parent = $boucle['pos_parent']; |
|
| 1043 | + $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1044 | + |
|
| 1045 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1046 | + |
|
| 1047 | + // boucle anonyme ? |
|
| 1048 | + if (!strlen($id_boucle)) { |
|
| 1049 | + $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + $pos_debut_boucle = $pos_courante; |
|
| 1053 | + |
|
| 1054 | + $pos_milieu = $pos_parent; |
|
| 1055 | + |
|
| 1056 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1057 | + if ($boucle['pos_precond'] !== false) { |
|
| 1058 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1059 | + |
|
| 1060 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 1061 | + $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1062 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1066 | + if ($boucle['pos_preaff'] !== false) { |
|
| 1067 | + $end_preaff = $pos_debut_boucle; |
|
| 1068 | + |
|
| 1069 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1070 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1071 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + $result->id_boucle = $id_boucle; |
|
| 1075 | + |
|
| 1076 | + if ( |
|
| 1077 | + !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1078 | + or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1079 | + or $pos_match > $pos_milieu |
|
| 1080 | + ) { |
|
| 1081 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1082 | + erreur_squelette($err_b, $result); |
|
| 1083 | + |
|
| 1084 | + $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1085 | + $pos_debut_texte = $pos_courante + 1; |
|
| 1086 | + continue; |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + $result->type_requete = $match[0]; |
|
| 1090 | + $pos_milieu += strlen($match[0]); |
|
| 1091 | + $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1092 | + |
|
| 1093 | + $type = $match[1]; |
|
| 1094 | + $jointures = trim($match[2]); |
|
| 1095 | + $table_optionnelle = ($match[3]); |
|
| 1096 | + if ($jointures) { |
|
| 1097 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1098 | + // ou elles seront completees des jointures declarees |
|
| 1099 | + $result->jointures_explicites = $jointures; |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + if ($table_optionnelle) { |
|
| 1103 | + $result->table_optionnelle = $type; |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1107 | + // Resultat mis dans result->param |
|
| 1108 | + $pos_fin_criteres = $pos_milieu; |
|
| 1109 | + phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1110 | + |
|
| 1111 | + // En 2e passe result->criteres contiendra un tableau |
|
| 1112 | + // pour l'instant on met le source (chaine) : |
|
| 1113 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1114 | + $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1115 | + $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1116 | + $pos_milieu = $pos_fin_criteres; |
|
| 1117 | + |
|
| 1118 | + // |
|
| 1119 | + // Recuperer la fin : |
|
| 1120 | + // |
|
| 1121 | + if ($texte[$pos_milieu] === '/') { |
|
| 1122 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 1123 | + $pos_courante += 2; |
|
| 1124 | + $result->milieu = ''; |
|
| 1125 | + } else { |
|
| 1126 | + $pos_milieu += 1; |
|
| 1127 | + |
|
| 1128 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1129 | + $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1130 | + if ($pos_fin === false) { |
|
| 1131 | + $err_b = [ |
|
| 1132 | + 'zbug_erreur_boucle_fermant', |
|
| 1133 | + ['id' => $id_boucle] |
|
| 1134 | + ]; |
|
| 1135 | + erreur_squelette($err_b, $result); |
|
| 1136 | + $pos_courante += strlen($fin_boucle); |
|
| 1137 | + } |
|
| 1138 | + else { |
|
| 1139 | + // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1140 | + // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1141 | + $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1142 | + $search_from = $pos_milieu; |
|
| 1143 | + $nb_open = 1; |
|
| 1144 | + $nb_close = 1; |
|
| 1145 | + $maxiter = 0; |
|
| 1146 | + do { |
|
| 1147 | + while ( |
|
| 1148 | + $nb_close < $nb_open |
|
| 1149 | + and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1150 | + ) { |
|
| 1151 | + $nb_close++; |
|
| 1152 | + $pos_fin = $p; |
|
| 1153 | + } |
|
| 1154 | + // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1155 | + if ($nb_close < $nb_open) { |
|
| 1156 | + break; |
|
| 1157 | + } |
|
| 1158 | + while ( |
|
| 1159 | + $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1160 | + and $p < $pos_fin |
|
| 1161 | + ) { |
|
| 1162 | + $nb_open++; |
|
| 1163 | + $search_from = $p + 1; |
|
| 1164 | + } |
|
| 1165 | + } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1166 | + |
|
| 1167 | + $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1168 | + } |
|
| 1169 | + $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1173 | + $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1174 | + |
|
| 1175 | + // |
|
| 1176 | + // 1. Partie conditionnelle apres ? |
|
| 1177 | + // |
|
| 1178 | + if ($boucle['pos_postcond']) { |
|
| 1179 | + $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1180 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1181 | + $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + |
|
| 1185 | + // |
|
| 1186 | + // 2. Partie alternative apres ? |
|
| 1187 | + // |
|
| 1188 | + $ligne_altern = $ligne_suite; |
|
| 1189 | + if ($boucle['pos_altern']) { |
|
| 1190 | + $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1191 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1192 | + $pos_courante = $boucle['pos_altern_inside']; |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + // |
|
| 1196 | + // 3. Partie footer non alternative ? |
|
| 1197 | + // |
|
| 1198 | + $ligne_postaff = $ligne_suite; |
|
| 1199 | + if ($boucle['pos_postaff']) { |
|
| 1200 | + $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1201 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1202 | + $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + $result->ligne = $ligne_preaff; |
|
| 1206 | + |
|
| 1207 | + if ($p = strpos($type, ':')) { |
|
| 1208 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1209 | + $type = substr($type, $p + 1); |
|
| 1210 | + } |
|
| 1211 | + $soustype = strtolower($type); |
|
| 1212 | + |
|
| 1213 | + if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1214 | + $soustype = $type; |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + $result->type_requete = $soustype; |
|
| 1218 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1219 | + if (!is_array($result->param)) { |
|
| 1220 | + $err_b = true; |
|
| 1221 | + } else { |
|
| 1222 | + phraser_criteres($result->param, $result); |
|
| 1223 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1224 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1225 | + $args = $result->param; |
|
| 1226 | + array_unshift( |
|
| 1227 | + $args, |
|
| 1228 | + substr($type, strlen(TYPE_RECURSIF)) |
|
| 1229 | + ); |
|
| 1230 | + $result->param = $args; |
|
| 1231 | + } |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1235 | + $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1236 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1237 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1238 | + // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1239 | + if (empty($boucles[$id_boucle])) { |
|
| 1240 | + $boucles[$id_boucle] = null; |
|
| 1241 | + } |
|
| 1242 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1243 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1244 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1245 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1246 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1247 | + |
|
| 1248 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1249 | + if ($err_b) { |
|
| 1250 | + $result->type_requete = false; |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + // Verifier qu'il n'y a pas double definition |
|
| 1254 | + // apres analyse des sous-parties (pas avant). |
|
| 1255 | + if (!empty($boucles[$id_boucle])) { |
|
| 1256 | + if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1257 | + $err_b_d = [ |
|
| 1258 | + 'zbug_erreur_boucle_double', |
|
| 1259 | + ['id' => $id_boucle] |
|
| 1260 | + ]; |
|
| 1261 | + erreur_squelette($err_b_d, $result); |
|
| 1262 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1263 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1264 | + } |
|
| 1265 | + } else { |
|
| 1266 | + $boucles[$id_boucle] = $result; |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1270 | + $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1271 | + $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1272 | + $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1273 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1274 | + |
|
| 1275 | + // phraser la partie avant le debut de la boucle |
|
| 1276 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1277 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1278 | + |
|
| 1279 | + $ligne_debut_texte = $ligne_suite; |
|
| 1280 | + $pos_debut_texte = $pos_courante; |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1284 | + |
|
| 1285 | + return $all_res; |
|
| 1286 | 1286 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | array_shift($p->param); |
| 53 | 53 | $p->etoile = '*'; |
| 54 | 54 | spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
| 55 | - } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 55 | + } elseif (preg_match('/^'.NOM_DE_CHAMP.'(.*)$/sS', $nom, $m)) { |
|
| 56 | 56 | $champ = new Champ(); |
| 57 | 57 | $champ->nom_boucle = $m[2]; |
| 58 | 58 | $champ->nom_champ = $m[3]; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $p->param[0][1] = [$c]; |
| 129 | 129 | $p->param[0][0] = ''; |
| 130 | 130 | $p->fonctions = []; |
| 131 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 131 | + spip_log('FORMULAIRE_RECHERCHE avec filtre '.$c->texte, 'vieilles_defs'); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Les fonctions de ce fichier sont appelees en certains points |
@@ -25,193 +25,193 @@ discard block |
||
| 25 | 25 | // -> https://www.spip.net/fr_article901.html |
| 26 | 26 | |
| 27 | 27 | function phraser_vieux_logos(&$p) { |
| 28 | - if ($p->param[0][0]) { |
|
| 29 | - $args = ['']; |
|
| 30 | - } else { |
|
| 31 | - $args = array_shift($p->param); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - foreach ($p->param as $couple) { |
|
| 35 | - $nom = trim($couple[0]); |
|
| 36 | - if ($nom == '') { |
|
| 37 | - array_shift($p->param); |
|
| 38 | - break; |
|
| 39 | - } |
|
| 40 | - $r = phraser_logo_faux_filtres($nom); |
|
| 41 | - if ($r === 0) { |
|
| 42 | - $c = new Texte(); |
|
| 43 | - $c->texte = $nom; |
|
| 44 | - $args[] = [$c]; |
|
| 45 | - array_shift($p->param); |
|
| 46 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | - } elseif ($r === 2) { |
|
| 48 | - $p->etoile = '**'; |
|
| 49 | - array_shift($p->param); |
|
| 50 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | - } elseif ($r === 1) { |
|
| 52 | - array_shift($p->param); |
|
| 53 | - $p->etoile = '*'; |
|
| 54 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | - } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | - $champ = new Champ(); |
|
| 57 | - $champ->nom_boucle = $m[2]; |
|
| 58 | - $champ->nom_champ = $m[3]; |
|
| 59 | - $champ->etoile = $m[5]; |
|
| 60 | - $champ = [$champ]; |
|
| 61 | - if ($m[6]) { |
|
| 62 | - $r = new Texte(); |
|
| 63 | - $r->texte = $m[6]; |
|
| 64 | - $champ[] = $r; |
|
| 65 | - } |
|
| 66 | - $args[] = $champ; |
|
| 67 | - array_shift($p->param); |
|
| 68 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 69 | - } // le cas else est la seule incompatibilite |
|
| 70 | - } |
|
| 71 | - array_unshift($p->param, $args); |
|
| 28 | + if ($p->param[0][0]) { |
|
| 29 | + $args = ['']; |
|
| 30 | + } else { |
|
| 31 | + $args = array_shift($p->param); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + foreach ($p->param as $couple) { |
|
| 35 | + $nom = trim($couple[0]); |
|
| 36 | + if ($nom == '') { |
|
| 37 | + array_shift($p->param); |
|
| 38 | + break; |
|
| 39 | + } |
|
| 40 | + $r = phraser_logo_faux_filtres($nom); |
|
| 41 | + if ($r === 0) { |
|
| 42 | + $c = new Texte(); |
|
| 43 | + $c->texte = $nom; |
|
| 44 | + $args[] = [$c]; |
|
| 45 | + array_shift($p->param); |
|
| 46 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | + } elseif ($r === 2) { |
|
| 48 | + $p->etoile = '**'; |
|
| 49 | + array_shift($p->param); |
|
| 50 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | + } elseif ($r === 1) { |
|
| 52 | + array_shift($p->param); |
|
| 53 | + $p->etoile = '*'; |
|
| 54 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | + } elseif (preg_match('/^' . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | + $champ = new Champ(); |
|
| 57 | + $champ->nom_boucle = $m[2]; |
|
| 58 | + $champ->nom_champ = $m[3]; |
|
| 59 | + $champ->etoile = $m[5]; |
|
| 60 | + $champ = [$champ]; |
|
| 61 | + if ($m[6]) { |
|
| 62 | + $r = new Texte(); |
|
| 63 | + $r->texte = $m[6]; |
|
| 64 | + $champ[] = $r; |
|
| 65 | + } |
|
| 66 | + $args[] = $champ; |
|
| 67 | + array_shift($p->param); |
|
| 68 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 69 | + } // le cas else est la seule incompatibilite |
|
| 70 | + } |
|
| 71 | + array_unshift($p->param, $args); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | function phraser_logo_faux_filtres($nom) { |
| 76 | - switch ($nom) { |
|
| 77 | - case 'top': |
|
| 78 | - case 'left': |
|
| 79 | - case 'right': |
|
| 80 | - case 'center': |
|
| 81 | - case 'bottom': |
|
| 82 | - return 0; |
|
| 83 | - case 'lien': |
|
| 84 | - return 1; |
|
| 85 | - case 'fichier': |
|
| 86 | - return 2; |
|
| 87 | - default: |
|
| 88 | - return $nom; |
|
| 89 | - } |
|
| 76 | + switch ($nom) { |
|
| 77 | + case 'top': |
|
| 78 | + case 'left': |
|
| 79 | + case 'right': |
|
| 80 | + case 'center': |
|
| 81 | + case 'bottom': |
|
| 82 | + return 0; |
|
| 83 | + case 'lien': |
|
| 84 | + return 1; |
|
| 85 | + case 'fichier': |
|
| 86 | + return 2; |
|
| 87 | + default: |
|
| 88 | + return $nom; |
|
| 89 | + } |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | |
| 93 | 93 | // La balise embed_document est a present le modele emb |
| 94 | 94 | |
| 95 | 95 | function phraser_vieux_emb(&$p) { |
| 96 | - if (!is_array($p->param)) { |
|
| 97 | - $p->param = []; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // Produire le premier argument {emb} |
|
| 101 | - $texte = new Texte(); |
|
| 102 | - $texte->texte = 'emb'; |
|
| 103 | - $param = ['', [$texte]]; |
|
| 104 | - |
|
| 105 | - // Transformer les filtres en arguments |
|
| 106 | - for ($i = 0; $i < (is_countable($p->param) ? count($p->param) : 0); $i++) { |
|
| 107 | - if ($p->param[$i][0]) { |
|
| 108 | - if (!strstr($p->param[$i][0], '=')) { |
|
| 109 | - break; |
|
| 110 | - }# on a rencontre un vrai filtre, c'est fini |
|
| 111 | - $texte = new Texte(); |
|
| 112 | - $texte->texte = $p->param[$i][0]; |
|
| 113 | - $param[] = [$texte]; |
|
| 114 | - } |
|
| 115 | - array_shift($p->param); |
|
| 116 | - } |
|
| 117 | - array_unshift($p->param, $param); |
|
| 118 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 119 | - $p->nom_champ = 'MODELE'; |
|
| 96 | + if (!is_array($p->param)) { |
|
| 97 | + $p->param = []; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // Produire le premier argument {emb} |
|
| 101 | + $texte = new Texte(); |
|
| 102 | + $texte->texte = 'emb'; |
|
| 103 | + $param = ['', [$texte]]; |
|
| 104 | + |
|
| 105 | + // Transformer les filtres en arguments |
|
| 106 | + for ($i = 0; $i < (is_countable($p->param) ? count($p->param) : 0); $i++) { |
|
| 107 | + if ($p->param[$i][0]) { |
|
| 108 | + if (!strstr($p->param[$i][0], '=')) { |
|
| 109 | + break; |
|
| 110 | + }# on a rencontre un vrai filtre, c'est fini |
|
| 111 | + $texte = new Texte(); |
|
| 112 | + $texte->texte = $p->param[$i][0]; |
|
| 113 | + $param[] = [$texte]; |
|
| 114 | + } |
|
| 115 | + array_shift($p->param); |
|
| 116 | + } |
|
| 117 | + array_unshift($p->param, $param); |
|
| 118 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 119 | + $p->nom_champ = 'MODELE'; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // Vieux formulaire de recherch |
| 123 | 123 | |
| 124 | 124 | function phraser_vieux_recherche($p) { |
| 125 | - if ($p->param[0][0]) { |
|
| 126 | - $c = new Texte(); |
|
| 127 | - $c->texte = $p->param[0][0]; |
|
| 128 | - $p->param[0][1] = [$c]; |
|
| 129 | - $p->param[0][0] = ''; |
|
| 130 | - $p->fonctions = []; |
|
| 131 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 132 | - } |
|
| 125 | + if ($p->param[0][0]) { |
|
| 126 | + $c = new Texte(); |
|
| 127 | + $c->texte = $p->param[0][0]; |
|
| 128 | + $p->param[0][1] = [$c]; |
|
| 129 | + $p->param[0][0] = ''; |
|
| 130 | + $p->fonctions = []; |
|
| 131 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 132 | + } |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // Gerer la notation [(#EXPOSER|on,off)] |
| 136 | 136 | function phraser_vieux_exposer($p) { |
| 137 | - if ($a = $p->fonctions) { |
|
| 138 | - preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 139 | - $args = []; |
|
| 140 | - if ($regs[1]) { |
|
| 141 | - $a = new Texte(); |
|
| 142 | - $a->texte = $regs[1]; |
|
| 143 | - $args = ['', [$a]]; |
|
| 144 | - if ($regs[3]) { |
|
| 145 | - $a = new Texte(); |
|
| 146 | - $a->texte = $regs[3]; |
|
| 147 | - $args[] = [$a]; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $p->param[0] = $args; |
|
| 151 | - $p->fonctions = []; |
|
| 152 | - $p->nom_champ = 'EXPOSE'; |
|
| 153 | - } |
|
| 137 | + if ($a = $p->fonctions) { |
|
| 138 | + preg_match('#([^,]*)(,(.*))?#', $a[0][0], $regs); |
|
| 139 | + $args = []; |
|
| 140 | + if ($regs[1]) { |
|
| 141 | + $a = new Texte(); |
|
| 142 | + $a->texte = $regs[1]; |
|
| 143 | + $args = ['', [$a]]; |
|
| 144 | + if ($regs[3]) { |
|
| 145 | + $a = new Texte(); |
|
| 146 | + $a->texte = $regs[3]; |
|
| 147 | + $args[] = [$a]; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $p->param[0] = $args; |
|
| 151 | + $p->fonctions = []; |
|
| 152 | + $p->nom_champ = 'EXPOSE'; |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | function phraser_vieux_modele($p) { |
| 157 | - normaliser_args_inclumodel($p); |
|
| 157 | + normaliser_args_inclumodel($p); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | function phraser_vieux_inclu($p) { |
| 161 | - normaliser_args_inclumodel($p); |
|
| 161 | + normaliser_args_inclumodel($p); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | function normaliser_args_inclumodel($p) { |
| 165 | - $params = $p->param; |
|
| 166 | - if (!$params) { |
|
| 167 | - return; |
|
| 168 | - } |
|
| 169 | - $args = $params[0]; |
|
| 170 | - if ($args[0]) { |
|
| 171 | - return; |
|
| 172 | - } // filtre immediat |
|
| 173 | - array_shift($p->param); |
|
| 174 | - foreach ($p->param as $l) { |
|
| 175 | - if (!array_shift($l)) { |
|
| 176 | - $args = array_merge($args, $l); |
|
| 177 | - array_shift($p->param); |
|
| 178 | - } else { |
|
| 179 | - break; |
|
| 180 | - } // filtre |
|
| 181 | - } |
|
| 182 | - array_unshift($p->param, $args); |
|
| 165 | + $params = $p->param; |
|
| 166 | + if (!$params) { |
|
| 167 | + return; |
|
| 168 | + } |
|
| 169 | + $args = $params[0]; |
|
| 170 | + if ($args[0]) { |
|
| 171 | + return; |
|
| 172 | + } // filtre immediat |
|
| 173 | + array_shift($p->param); |
|
| 174 | + foreach ($p->param as $l) { |
|
| 175 | + if (!array_shift($l)) { |
|
| 176 | + $args = array_merge($args, $l); |
|
| 177 | + array_shift($p->param); |
|
| 178 | + } else { |
|
| 179 | + break; |
|
| 180 | + } // filtre |
|
| 181 | + } |
|
| 182 | + array_unshift($p->param, $args); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function normaliser_inclure($champ) { |
| 186 | - normaliser_args_inclumodel($champ); |
|
| 187 | - $l = $champ->param[0]; |
|
| 188 | - if (is_array($l) and !$l[0]) { |
|
| 189 | - foreach ($l as $k => $p) { |
|
| 190 | - if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 191 | - $p[0]->texte = trim($p[0]->texte); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - foreach ($l as $k => $p) { |
|
| 195 | - if ( |
|
| 196 | - !$p or $p[0]->type != 'texte' or |
|
| 197 | - !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 198 | - ) { |
|
| 199 | - continue; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($r[1]) { |
|
| 203 | - $p[0]->texte = $r[1]; |
|
| 204 | - } else { |
|
| 205 | - unset($p[0]); |
|
| 206 | - } |
|
| 207 | - $champ->texte = $p; |
|
| 208 | - unset($champ->param[0][$k]); |
|
| 209 | - if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) { |
|
| 210 | - array_shift($champ->param); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - return; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - spip_log('inclure sans fond ni fichier'); |
|
| 186 | + normaliser_args_inclumodel($champ); |
|
| 187 | + $l = $champ->param[0]; |
|
| 188 | + if (is_array($l) and !$l[0]) { |
|
| 189 | + foreach ($l as $k => $p) { |
|
| 190 | + if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 191 | + $p[0]->texte = trim($p[0]->texte); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + foreach ($l as $k => $p) { |
|
| 195 | + if ( |
|
| 196 | + !$p or $p[0]->type != 'texte' or |
|
| 197 | + !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 198 | + ) { |
|
| 199 | + continue; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($r[1]) { |
|
| 203 | + $p[0]->texte = $r[1]; |
|
| 204 | + } else { |
|
| 205 | + unset($p[0]); |
|
| 206 | + } |
|
| 207 | + $champ->texte = $p; |
|
| 208 | + unset($champ->param[0][$k]); |
|
| 209 | + if ((is_countable($champ->param[0]) ? count($champ->param[0]) : 0) == 1) { |
|
| 210 | + array_shift($champ->param); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + return; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + spip_log('inclure sans fond ni fichier'); |
|
| 217 | 217 | } |
@@ -207,8 +207,7 @@ discard block |
||
| 207 | 207 | $pagination['type_pagination'] = $modele; |
| 208 | 208 | if (trouver_fond('pagination_' . $modele, 'modeles')) { |
| 209 | 209 | $modele = '_' . $modele; |
| 210 | - } |
|
| 211 | - else { |
|
| 210 | + } else { |
|
| 212 | 211 | $modele = ''; |
| 213 | 212 | } |
| 214 | 213 | } |
@@ -295,8 +294,7 @@ discard block |
||
| 295 | 294 | if ($ids) { |
| 296 | 295 | $ids = array_column($ids, 'id_objet'); |
| 297 | 296 | return implode(',', $ids); |
| 298 | - } |
|
| 299 | - else { |
|
| 297 | + } else { |
|
| 300 | 298 | return '0'; |
| 301 | 299 | } |
| 302 | 300 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $texte = $intro; |
| 85 | 85 | } else { |
| 86 | 86 | if ( |
| 87 | - strpos("\n" . $texte, "\n|") === false |
|
| 87 | + strpos("\n".$texte, "\n|") === false |
|
| 88 | 88 | and strlen($texte) > 2.5 * $longueur |
| 89 | 89 | ) { |
| 90 | 90 | if (strpos($texte, '<multi') !== false) { |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | if ($pas < 1) { |
| 169 | 169 | return ''; |
| 170 | 170 | } |
| 171 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 171 | + $ancre = 'pagination'.$nom; // #pagination_articles |
|
| 172 | + $debut = 'debut'.$nom; // 'debut_articles' |
|
| 173 | 173 | |
| 174 | 174 | // n'afficher l'ancre qu'une fois |
| 175 | 175 | if (!isset($ancres[$ancre])) { |
| 176 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 176 | + $bloc_ancre = $ancres[$ancre] = "<a id='".$ancre."' class='pagination_ancre'></a>"; |
|
| 177 | 177 | } else { |
| 178 | 178 | $bloc_ancre = ''; |
| 179 | 179 | } |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | if ($modele) { |
| 207 | 207 | $pagination['type_pagination'] = $modele; |
| 208 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | - $modele = '_' . $modele; |
|
| 208 | + if (trouver_fond('pagination_'.$modele, 'modeles')) { |
|
| 209 | + $modele = '_'.$modele; |
|
| 210 | 210 | } |
| 211 | 211 | else { |
| 212 | 212 | $modele = ''; |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | function lister_objets_avec_logos($type) { |
| 292 | 292 | |
| 293 | 293 | $objet = objet_type($type); |
| 294 | - $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 294 | + $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode='.sql_quote('logoon').' AND L.objet='.sql_quote($objet)); |
|
| 295 | 295 | if ($ids) { |
| 296 | 296 | $ids = array_column($ids, 'id_objet'); |
| 297 | 297 | return implode(',', $ids); |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | |
| 485 | 485 | // Classes : on indique le sens de tri et l'item exposé |
| 486 | 486 | if (!$is_sens_fixe) { |
| 487 | - $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 487 | + $classe .= ' item-tri item-tri_'.($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 488 | 488 | } |
| 489 | 489 | if ($champ_ou_sens === $tri_champ) { |
| 490 | 490 | $classe .= ' item-tri_actif'; |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | */ |
| 524 | 524 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 525 | 525 | if (strncmp($t, 'multi ', 6) == 0) { |
| 526 | - return 'multi' . $senstri; |
|
| 526 | + return 'multi'.$senstri; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | $champ = $t; |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | case 'sinum ': |
| 558 | 558 | return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
| 559 | 559 | default: |
| 560 | - return $champ . $senstri; |
|
| 560 | + return $champ.$senstri; |
|
| 561 | 561 | } |
| 562 | 562 | } |
| 563 | 563 | |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | // public/interfaces definit des traitements sur les champs qui utilisent des fonctions de inc/texte |
@@ -55,75 +55,75 @@ discard block |
||
| 55 | 55 | * Introduction calculée |
| 56 | 56 | **/ |
| 57 | 57 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 58 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 59 | - if (strlen($descriptif)) { |
|
| 60 | - return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // De preference ce qui est marque <intro>...</intro> |
|
| 64 | - $intro = ''; |
|
| 65 | - $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 66 | - while ($fin = strpos($texte, '</intro>')) { |
|
| 67 | - $zone = substr($texte, 0, $fin); |
|
| 68 | - $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 69 | - if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 70 | - $zone = substr($zone, $deb + 7); |
|
| 71 | - } |
|
| 72 | - $intro .= $zone; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 76 | - // qui inclus raccourcis et modeles |
|
| 77 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 78 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 79 | - // des surcharges et enrichissement de propre |
|
| 80 | - // couper doit se faire apres propre |
|
| 81 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 82 | - |
|
| 83 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 84 | - // large et en se mefiant des tableaux #1323 |
|
| 85 | - |
|
| 86 | - if (strlen($intro)) { |
|
| 87 | - $texte = $intro; |
|
| 88 | - } else { |
|
| 89 | - if ( |
|
| 90 | - strpos("\n" . $texte, "\n|") === false |
|
| 91 | - and strlen($texte) > 2.5 * $longueur |
|
| 92 | - ) { |
|
| 93 | - if (strpos($texte, '<multi') !== false) { |
|
| 94 | - $texte = extraire_multi($texte); |
|
| 95 | - } |
|
| 96 | - $texte = couper($texte, 2 * $longueur); |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // ne pas tenir compte des notes |
|
| 101 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 102 | - $notes('', 'empiler'); |
|
| 103 | - } |
|
| 104 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 105 | - // dans l'introduction. |
|
| 106 | - $texte = supprime_img($texte, ''); |
|
| 107 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 108 | - |
|
| 109 | - if ($notes) { |
|
| 110 | - $notes('', 'depiler'); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 114 | - $suite = _INTRODUCTION_SUITE; |
|
| 115 | - } |
|
| 116 | - $texte = couper($texte, $longueur, $suite); |
|
| 117 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 118 | - $texte = typo($texte, true, $connect, []); |
|
| 119 | - |
|
| 120 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 121 | - // une introduction a tojours un <p> |
|
| 122 | - if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 123 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return $texte; |
|
| 58 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 59 | + if (strlen($descriptif)) { |
|
| 60 | + return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // De preference ce qui est marque <intro>...</intro> |
|
| 64 | + $intro = ''; |
|
| 65 | + $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 66 | + while ($fin = strpos($texte, '</intro>')) { |
|
| 67 | + $zone = substr($texte, 0, $fin); |
|
| 68 | + $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 69 | + if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 70 | + $zone = substr($zone, $deb + 7); |
|
| 71 | + } |
|
| 72 | + $intro .= $zone; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 76 | + // qui inclus raccourcis et modeles |
|
| 77 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 78 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 79 | + // des surcharges et enrichissement de propre |
|
| 80 | + // couper doit se faire apres propre |
|
| 81 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 82 | + |
|
| 83 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 84 | + // large et en se mefiant des tableaux #1323 |
|
| 85 | + |
|
| 86 | + if (strlen($intro)) { |
|
| 87 | + $texte = $intro; |
|
| 88 | + } else { |
|
| 89 | + if ( |
|
| 90 | + strpos("\n" . $texte, "\n|") === false |
|
| 91 | + and strlen($texte) > 2.5 * $longueur |
|
| 92 | + ) { |
|
| 93 | + if (strpos($texte, '<multi') !== false) { |
|
| 94 | + $texte = extraire_multi($texte); |
|
| 95 | + } |
|
| 96 | + $texte = couper($texte, 2 * $longueur); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // ne pas tenir compte des notes |
|
| 101 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 102 | + $notes('', 'empiler'); |
|
| 103 | + } |
|
| 104 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 105 | + // dans l'introduction. |
|
| 106 | + $texte = supprime_img($texte, ''); |
|
| 107 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 108 | + |
|
| 109 | + if ($notes) { |
|
| 110 | + $notes('', 'depiler'); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 114 | + $suite = _INTRODUCTION_SUITE; |
|
| 115 | + } |
|
| 116 | + $texte = couper($texte, $longueur, $suite); |
|
| 117 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 118 | + $texte = typo($texte, true, $connect, []); |
|
| 119 | + |
|
| 120 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 121 | + // une introduction a tojours un <p> |
|
| 122 | + if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 123 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return $texte; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | |
@@ -158,73 +158,73 @@ discard block |
||
| 158 | 158 | * Code HTML de la pagination |
| 159 | 159 | **/ |
| 160 | 160 | function filtre_pagination_dist( |
| 161 | - $total, |
|
| 162 | - $nom, |
|
| 163 | - $position, |
|
| 164 | - $pas, |
|
| 165 | - $liste = true, |
|
| 166 | - $modele = '', |
|
| 167 | - string $connect = '', |
|
| 168 | - $env = [] |
|
| 161 | + $total, |
|
| 162 | + $nom, |
|
| 163 | + $position, |
|
| 164 | + $pas, |
|
| 165 | + $liste = true, |
|
| 166 | + $modele = '', |
|
| 167 | + string $connect = '', |
|
| 168 | + $env = [] |
|
| 169 | 169 | ) { |
| 170 | - static $ancres = []; |
|
| 171 | - if ($pas < 1) { |
|
| 172 | - return ''; |
|
| 173 | - } |
|
| 174 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 175 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 176 | - |
|
| 177 | - // n'afficher l'ancre qu'une fois |
|
| 178 | - if (!isset($ancres[$ancre])) { |
|
| 179 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 180 | - } else { |
|
| 181 | - $bloc_ancre = ''; |
|
| 182 | - } |
|
| 183 | - // liste = false : on ne veut que l'ancre |
|
| 184 | - if (!$liste) { |
|
| 185 | - return $ancres[$ancre]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $self = (empty($env['self']) ? self() : $env['self']); |
|
| 189 | - $pagination = [ |
|
| 190 | - 'debut' => $debut, |
|
| 191 | - 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 192 | - 'total' => $total, |
|
| 193 | - 'position' => intval($position), |
|
| 194 | - 'pas' => $pas, |
|
| 195 | - 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 196 | - 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 197 | - 'ancre' => $ancre, |
|
| 198 | - 'bloc_ancre' => $bloc_ancre |
|
| 199 | - ]; |
|
| 200 | - if (is_array($env)) { |
|
| 201 | - $pagination = array_merge($env, $pagination); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // Pas de pagination |
|
| 205 | - if ($pagination['nombre_pages'] <= 1) { |
|
| 206 | - return ''; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if ($modele) { |
|
| 210 | - $pagination['type_pagination'] = $modele; |
|
| 211 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 212 | - $modele = '_' . $modele; |
|
| 213 | - } |
|
| 214 | - else { |
|
| 215 | - $modele = ''; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 220 | - define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 221 | - } |
|
| 222 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 223 | - define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 170 | + static $ancres = []; |
|
| 171 | + if ($pas < 1) { |
|
| 172 | + return ''; |
|
| 173 | + } |
|
| 174 | + $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 175 | + $debut = 'debut' . $nom; // 'debut_articles' |
|
| 176 | + |
|
| 177 | + // n'afficher l'ancre qu'une fois |
|
| 178 | + if (!isset($ancres[$ancre])) { |
|
| 179 | + $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 180 | + } else { |
|
| 181 | + $bloc_ancre = ''; |
|
| 182 | + } |
|
| 183 | + // liste = false : on ne veut que l'ancre |
|
| 184 | + if (!$liste) { |
|
| 185 | + return $ancres[$ancre]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $self = (empty($env['self']) ? self() : $env['self']); |
|
| 189 | + $pagination = [ |
|
| 190 | + 'debut' => $debut, |
|
| 191 | + 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 192 | + 'total' => $total, |
|
| 193 | + 'position' => intval($position), |
|
| 194 | + 'pas' => $pas, |
|
| 195 | + 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 196 | + 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 197 | + 'ancre' => $ancre, |
|
| 198 | + 'bloc_ancre' => $bloc_ancre |
|
| 199 | + ]; |
|
| 200 | + if (is_array($env)) { |
|
| 201 | + $pagination = array_merge($env, $pagination); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // Pas de pagination |
|
| 205 | + if ($pagination['nombre_pages'] <= 1) { |
|
| 206 | + return ''; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if ($modele) { |
|
| 210 | + $pagination['type_pagination'] = $modele; |
|
| 211 | + if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 212 | + $modele = '_' . $modele; |
|
| 213 | + } |
|
| 214 | + else { |
|
| 215 | + $modele = ''; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 220 | + define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 221 | + } |
|
| 222 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 223 | + define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | |
@@ -243,44 +243,44 @@ discard block |
||
| 243 | 243 | * Liste (première page, dernière page). |
| 244 | 244 | **/ |
| 245 | 245 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 246 | - if ($max <= 0 or $max >= $nombre) { |
|
| 247 | - return [1, $nombre]; |
|
| 248 | - } |
|
| 249 | - if ($max <= 1) { |
|
| 250 | - return [$courante, $courante]; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 254 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 255 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 256 | - |
|
| 257 | - return [$premiere, $derniere]; |
|
| 246 | + if ($max <= 0 or $max >= $nombre) { |
|
| 247 | + return [1, $nombre]; |
|
| 248 | + } |
|
| 249 | + if ($max <= 1) { |
|
| 250 | + return [$courante, $courante]; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 254 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 255 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 256 | + |
|
| 257 | + return [$premiere, $derniere]; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | function filtre_pagination_affiche_texte_lien_page_dist($type_pagination, $numero_page, $rang_item) { |
| 261 | - if ($numero_page === 'tous') { |
|
| 262 | - return '∞'; |
|
| 263 | - } |
|
| 264 | - if ($numero_page === 'prev') { |
|
| 265 | - return '<'; |
|
| 266 | - } |
|
| 267 | - if ($numero_page === 'next') { |
|
| 268 | - return '>'; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - switch ($type_pagination) { |
|
| 272 | - case 'resultats': |
|
| 273 | - return $rang_item + 1; // 1 11 21 31... |
|
| 274 | - case 'naturel': |
|
| 275 | - return $rang_item ?: 1; // 1 10 20 30... |
|
| 276 | - case 'rang': |
|
| 277 | - return $rang_item; // 0 10 20 30... |
|
| 278 | - |
|
| 279 | - case 'page': |
|
| 280 | - case 'prive': |
|
| 281 | - default: |
|
| 282 | - return $numero_page; // 1 2 3 4 5... |
|
| 283 | - } |
|
| 261 | + if ($numero_page === 'tous') { |
|
| 262 | + return '∞'; |
|
| 263 | + } |
|
| 264 | + if ($numero_page === 'prev') { |
|
| 265 | + return '<'; |
|
| 266 | + } |
|
| 267 | + if ($numero_page === 'next') { |
|
| 268 | + return '>'; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + switch ($type_pagination) { |
|
| 272 | + case 'resultats': |
|
| 273 | + return $rang_item + 1; // 1 11 21 31... |
|
| 274 | + case 'naturel': |
|
| 275 | + return $rang_item ?: 1; // 1 10 20 30... |
|
| 276 | + case 'rang': |
|
| 277 | + return $rang_item; // 0 10 20 30... |
|
| 278 | + |
|
| 279 | + case 'page': |
|
| 280 | + case 'prive': |
|
| 281 | + default: |
|
| 282 | + return $numero_page; // 1 2 3 4 5... |
|
| 283 | + } |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -293,15 +293,15 @@ discard block |
||
| 293 | 293 | **/ |
| 294 | 294 | function lister_objets_avec_logos($type) { |
| 295 | 295 | |
| 296 | - $objet = objet_type($type); |
|
| 297 | - $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 298 | - if ($ids) { |
|
| 299 | - $ids = array_column($ids, 'id_objet'); |
|
| 300 | - return implode(',', $ids); |
|
| 301 | - } |
|
| 302 | - else { |
|
| 303 | - return '0'; |
|
| 304 | - } |
|
| 296 | + $objet = objet_type($type); |
|
| 297 | + $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 298 | + if ($ids) { |
|
| 299 | + $ids = array_column($ids, 'id_objet'); |
|
| 300 | + return implode(',', $ids); |
|
| 301 | + } |
|
| 302 | + else { |
|
| 303 | + return '0'; |
|
| 304 | + } |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | |
@@ -317,14 +317,14 @@ discard block |
||
| 317 | 317 | * Code HTML des notes |
| 318 | 318 | **/ |
| 319 | 319 | function calculer_notes() { |
| 320 | - $r = ''; |
|
| 321 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 322 | - $r = $notes([]); |
|
| 323 | - $notes('', 'depiler'); |
|
| 324 | - $notes('', 'empiler'); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - return $r; |
|
| 320 | + $r = ''; |
|
| 321 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 322 | + $r = $notes([]); |
|
| 323 | + $notes('', 'depiler'); |
|
| 324 | + $notes('', 'empiler'); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + return $r; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | |
@@ -341,10 +341,10 @@ discard block |
||
| 341 | 341 | * @return string |
| 342 | 342 | */ |
| 343 | 343 | function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) { |
| 344 | - $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 345 | - $res = array_column($res, 'rang_lien', $objet_source); |
|
| 344 | + $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 345 | + $res = array_column($res, 'rang_lien', $objet_source); |
|
| 346 | 346 | |
| 347 | - return ($res[$ids] ?? ''); |
|
| 347 | + return ($res[$ids] ?? ''); |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | |
@@ -361,19 +361,19 @@ discard block |
||
| 361 | 361 | * @private |
| 362 | 362 | */ |
| 363 | 363 | function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) { |
| 364 | - static $liens = []; |
|
| 365 | - if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 366 | - include_spip('action/editer_liens'); |
|
| 367 | - // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 368 | - if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 369 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 370 | - } else { |
|
| 371 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 375 | - } |
|
| 376 | - return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 364 | + static $liens = []; |
|
| 365 | + if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 366 | + include_spip('action/editer_liens'); |
|
| 367 | + // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 368 | + if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 369 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 370 | + } else { |
|
| 371 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 375 | + } |
|
| 376 | + return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -387,24 +387,24 @@ discard block |
||
| 387 | 387 | * @return int|string |
| 388 | 388 | */ |
| 389 | 389 | function calculer_rang_smart($titre, $objet_source, $id, $env) { |
| 390 | - // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 391 | - // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 392 | - if ( |
|
| 393 | - isset($env['form']) and $env['form'] |
|
| 394 | - and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 395 | - and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 396 | - and $r = objet_associable($env['_objet_lien']) |
|
| 397 | - and [$p, $table_lien] = $r |
|
| 398 | - and lien_triables($table_lien) |
|
| 399 | - and isset($env['objet']) and $env['objet'] |
|
| 400 | - and isset($env['id_objet']) and $env['id_objet'] |
|
| 401 | - and $objet_source |
|
| 402 | - and $id = intval($id) |
|
| 403 | - ) { |
|
| 404 | - $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 405 | - return ($rang ?: ''); |
|
| 406 | - } |
|
| 407 | - return recuperer_numero($titre); |
|
| 390 | + // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 391 | + // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 392 | + if ( |
|
| 393 | + isset($env['form']) and $env['form'] |
|
| 394 | + and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 395 | + and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 396 | + and $r = objet_associable($env['_objet_lien']) |
|
| 397 | + and [$p, $table_lien] = $r |
|
| 398 | + and lien_triables($table_lien) |
|
| 399 | + and isset($env['objet']) and $env['objet'] |
|
| 400 | + and isset($env['id_objet']) and $env['id_objet'] |
|
| 401 | + and $objet_source |
|
| 402 | + and $id = intval($id) |
|
| 403 | + ) { |
|
| 404 | + $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 405 | + return ($rang ?: ''); |
|
| 406 | + } |
|
| 407 | + return recuperer_numero($titre); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -431,72 +431,72 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | function calculer_balise_tri(string $champ_ou_sens, string $libelle, string $classe, string $tri_nom, string $tri_champ, string $tri_sens, $liste_tri_sens_defaut): string { |
| 433 | 433 | |
| 434 | - $url = self('&'); |
|
| 435 | - $tri_sens = (int) $tri_sens; |
|
| 436 | - $alias_sens = [ |
|
| 437 | - '<' => -1, |
|
| 438 | - '>' => 1, |
|
| 439 | - 'inverse' => -1, |
|
| 440 | - ]; |
|
| 441 | - |
|
| 442 | - // Normaliser la liste des sens de tri par défaut |
|
| 443 | - // On ajoute un jocker pour les champs non présents dans la liste |
|
| 444 | - // avec la valeur du 1er item de la liste, idem critère {tri} |
|
| 445 | - if (is_array($liste_tri_sens_defaut)) { |
|
| 446 | - $liste_tri_sens_defaut['*'] = array_values($liste_tri_sens_defaut)[0]; |
|
| 447 | - } else { |
|
| 448 | - $liste_tri_sens_defaut = [ |
|
| 449 | - '*' => (int) ($alias_sens[$liste_tri_sens_defaut] ?? $liste_tri_sens_defaut), |
|
| 450 | - ]; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // Les sens de tri actuel et nouveau : |
|
| 454 | - // Soit c'est un sens fixe donné en paramètre (< ou >) |
|
| 455 | - $is_sens_fixe = array_key_exists($champ_ou_sens, $alias_sens); |
|
| 456 | - if ($is_sens_fixe) { |
|
| 457 | - $tri_sens_actuel = $tri_sens; |
|
| 458 | - $tri_sens_nouveau = $alias_sens[$champ_ou_sens]; |
|
| 459 | - // Soit c'est le champ utilisé actuellement pour le tri → on inverse le sens |
|
| 460 | - } elseif ($champ_ou_sens === $tri_champ) { |
|
| 461 | - $tri_sens_actuel = $tri_sens; |
|
| 462 | - $tri_sens_nouveau = $tri_sens * -1; |
|
| 463 | - // Sinon c'est un nouveau champ, et on prend son tri par défaut |
|
| 464 | - } else { |
|
| 465 | - $tri_sens_actuel = $tri_sens_nouveau = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // URL : ajouter le champ sur lequel porte le tri |
|
| 469 | - if (!$is_sens_fixe) { |
|
| 470 | - $param_tri = "tri$tri_nom"; |
|
| 471 | - $url = parametre_url($url, $param_tri, $champ_ou_sens); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - // URL : n'ajouter le sens de tri que si nécessaire, |
|
| 475 | - // c.à.d différent du sens par défaut pour le champ |
|
| 476 | - $param_sens = "sens$tri_nom"; |
|
| 477 | - $tri_sens_defaut_champ = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 478 | - if ($tri_sens_nouveau !== $tri_sens_defaut_champ) { |
|
| 479 | - $url = parametre_url($url, $param_sens, $tri_sens_nouveau); |
|
| 480 | - } else { |
|
| 481 | - $url = parametre_url($url, $param_sens, ''); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - // Drapeau pour garder en session ? |
|
| 485 | - $param_memo = (!$is_sens_fixe ? $param_tri : $param_sens); |
|
| 486 | - $url = parametre_url($url, 'var_memotri', strncmp($tri_nom, 'session', 7) == 0 ? $param_memo : ''); |
|
| 487 | - |
|
| 488 | - // Classes : on indique le sens de tri et l'item exposé |
|
| 489 | - if (!$is_sens_fixe) { |
|
| 490 | - $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 491 | - } |
|
| 492 | - if ($champ_ou_sens === $tri_champ) { |
|
| 493 | - $classe .= ' item-tri_actif'; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - // Lien |
|
| 497 | - $balise = lien_ou_expose($url, $libelle, false, $classe); |
|
| 498 | - |
|
| 499 | - return $balise; |
|
| 434 | + $url = self('&'); |
|
| 435 | + $tri_sens = (int) $tri_sens; |
|
| 436 | + $alias_sens = [ |
|
| 437 | + '<' => -1, |
|
| 438 | + '>' => 1, |
|
| 439 | + 'inverse' => -1, |
|
| 440 | + ]; |
|
| 441 | + |
|
| 442 | + // Normaliser la liste des sens de tri par défaut |
|
| 443 | + // On ajoute un jocker pour les champs non présents dans la liste |
|
| 444 | + // avec la valeur du 1er item de la liste, idem critère {tri} |
|
| 445 | + if (is_array($liste_tri_sens_defaut)) { |
|
| 446 | + $liste_tri_sens_defaut['*'] = array_values($liste_tri_sens_defaut)[0]; |
|
| 447 | + } else { |
|
| 448 | + $liste_tri_sens_defaut = [ |
|
| 449 | + '*' => (int) ($alias_sens[$liste_tri_sens_defaut] ?? $liste_tri_sens_defaut), |
|
| 450 | + ]; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // Les sens de tri actuel et nouveau : |
|
| 454 | + // Soit c'est un sens fixe donné en paramètre (< ou >) |
|
| 455 | + $is_sens_fixe = array_key_exists($champ_ou_sens, $alias_sens); |
|
| 456 | + if ($is_sens_fixe) { |
|
| 457 | + $tri_sens_actuel = $tri_sens; |
|
| 458 | + $tri_sens_nouveau = $alias_sens[$champ_ou_sens]; |
|
| 459 | + // Soit c'est le champ utilisé actuellement pour le tri → on inverse le sens |
|
| 460 | + } elseif ($champ_ou_sens === $tri_champ) { |
|
| 461 | + $tri_sens_actuel = $tri_sens; |
|
| 462 | + $tri_sens_nouveau = $tri_sens * -1; |
|
| 463 | + // Sinon c'est un nouveau champ, et on prend son tri par défaut |
|
| 464 | + } else { |
|
| 465 | + $tri_sens_actuel = $tri_sens_nouveau = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // URL : ajouter le champ sur lequel porte le tri |
|
| 469 | + if (!$is_sens_fixe) { |
|
| 470 | + $param_tri = "tri$tri_nom"; |
|
| 471 | + $url = parametre_url($url, $param_tri, $champ_ou_sens); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + // URL : n'ajouter le sens de tri que si nécessaire, |
|
| 475 | + // c.à.d différent du sens par défaut pour le champ |
|
| 476 | + $param_sens = "sens$tri_nom"; |
|
| 477 | + $tri_sens_defaut_champ = (int) ($liste_tri_sens_defaut[$champ_ou_sens] ?? $liste_tri_sens_defaut['*']); |
|
| 478 | + if ($tri_sens_nouveau !== $tri_sens_defaut_champ) { |
|
| 479 | + $url = parametre_url($url, $param_sens, $tri_sens_nouveau); |
|
| 480 | + } else { |
|
| 481 | + $url = parametre_url($url, $param_sens, ''); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + // Drapeau pour garder en session ? |
|
| 485 | + $param_memo = (!$is_sens_fixe ? $param_tri : $param_sens); |
|
| 486 | + $url = parametre_url($url, 'var_memotri', strncmp($tri_nom, 'session', 7) == 0 ? $param_memo : ''); |
|
| 487 | + |
|
| 488 | + // Classes : on indique le sens de tri et l'item exposé |
|
| 489 | + if (!$is_sens_fixe) { |
|
| 490 | + $classe .= ' item-tri item-tri_' . ($tri_sens_actuel === 1 ? 'asc' : 'desc'); |
|
| 491 | + } |
|
| 492 | + if ($champ_ou_sens === $tri_champ) { |
|
| 493 | + $classe .= ' item-tri_actif'; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + // Lien |
|
| 497 | + $balise = lien_ou_expose($url, $libelle, false, $classe); |
|
| 498 | + |
|
| 499 | + return $balise; |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | * @return string |
| 513 | 513 | */ |
| 514 | 514 | function tri_protege_champ($t) { |
| 515 | - return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 515 | + return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -525,43 +525,43 @@ discard block |
||
| 525 | 525 | * @return string |
| 526 | 526 | */ |
| 527 | 527 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 528 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 529 | - return 'multi' . $senstri; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - $champ = $t; |
|
| 533 | - |
|
| 534 | - $prefixe = ''; |
|
| 535 | - foreach (['num ', 'sinum '] as $p) { |
|
| 536 | - if (strpos($t, $p) === 0) { |
|
| 537 | - $champ = substr($t, strlen($p)); |
|
| 538 | - $prefixe = $p; |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 543 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 544 | - |
|
| 545 | - if (is_array($from)) { |
|
| 546 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 547 | - foreach ($from as $idt => $table_sql) { |
|
| 548 | - if ( |
|
| 549 | - $desc = $trouver_table($table_sql) |
|
| 550 | - and isset($desc['field'][$champ]) |
|
| 551 | - ) { |
|
| 552 | - $champ = "$idt.$champ"; |
|
| 553 | - break; |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - switch ($prefixe) { |
|
| 558 | - case 'num ': |
|
| 559 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 560 | - case 'sinum ': |
|
| 561 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 562 | - default: |
|
| 563 | - return $champ . $senstri; |
|
| 564 | - } |
|
| 528 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 529 | + return 'multi' . $senstri; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + $champ = $t; |
|
| 533 | + |
|
| 534 | + $prefixe = ''; |
|
| 535 | + foreach (['num ', 'sinum '] as $p) { |
|
| 536 | + if (strpos($t, $p) === 0) { |
|
| 537 | + $champ = substr($t, strlen($p)); |
|
| 538 | + $prefixe = $p; |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 543 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 544 | + |
|
| 545 | + if (is_array($from)) { |
|
| 546 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 547 | + foreach ($from as $idt => $table_sql) { |
|
| 548 | + if ( |
|
| 549 | + $desc = $trouver_table($table_sql) |
|
| 550 | + and isset($desc['field'][$champ]) |
|
| 551 | + ) { |
|
| 552 | + $champ = "$idt.$champ"; |
|
| 553 | + break; |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + switch ($prefixe) { |
|
| 558 | + case 'num ': |
|
| 559 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 560 | + case 'sinum ': |
|
| 561 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 562 | + default: |
|
| 563 | + return $champ . $senstri; |
|
| 564 | + } |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
@@ -575,18 +575,18 @@ discard block |
||
| 575 | 575 | * @return string |
| 576 | 576 | */ |
| 577 | 577 | function tri_champ_select($t) { |
| 578 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 579 | - $t = substr($t, 6); |
|
| 580 | - $t = preg_replace(',\s,', '', $t); |
|
| 581 | - $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 582 | - |
|
| 583 | - return $t; |
|
| 584 | - } |
|
| 585 | - if (trim($t) == 'hasard') { |
|
| 586 | - return 'rand() AS hasard'; |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return "''"; |
|
| 578 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 579 | + $t = substr($t, 6); |
|
| 580 | + $t = preg_replace(',\s,', '', $t); |
|
| 581 | + $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 582 | + |
|
| 583 | + return $t; |
|
| 584 | + } |
|
| 585 | + if (trim($t) == 'hasard') { |
|
| 586 | + return 'rand() AS hasard'; |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return "''"; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -598,16 +598,16 @@ discard block |
||
| 598 | 598 | * @return string |
| 599 | 599 | */ |
| 600 | 600 | function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') { |
| 601 | - if (!is_array($valeurs)) { |
|
| 602 | - return ''; |
|
| 603 | - } |
|
| 604 | - $f = sql_serveur('quote', $serveur, true); |
|
| 605 | - if (!is_string($f) or !$f) { |
|
| 606 | - return ''; |
|
| 607 | - } |
|
| 608 | - $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 609 | - |
|
| 610 | - return $valeurs; |
|
| 601 | + if (!is_array($valeurs)) { |
|
| 602 | + return ''; |
|
| 603 | + } |
|
| 604 | + $f = sql_serveur('quote', $serveur, true); |
|
| 605 | + if (!is_string($f) or !$f) { |
|
| 606 | + return ''; |
|
| 607 | + } |
|
| 608 | + $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 609 | + |
|
| 610 | + return $valeurs; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -630,20 +630,20 @@ discard block |
||
| 630 | 630 | * Valeur $defaut sinon. |
| 631 | 631 | **/ |
| 632 | 632 | function appliquer_filtre_sinon($arg, $filtre, $args, $defaut = '') { |
| 633 | - // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 634 | - // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 635 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 636 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 637 | - $args[1] = $args[0]; |
|
| 638 | - $args[0] = $filtre; |
|
| 639 | - return image_graver(image_filtrer($args)); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - $f = chercher_filtre($filtre); |
|
| 643 | - if (!$f) { |
|
| 644 | - return $defaut; |
|
| 645 | - } |
|
| 646 | - array_shift($args); // enlever $arg |
|
| 647 | - array_shift($args); // enlever $filtre |
|
| 648 | - return $f($arg, ...$args); |
|
| 633 | + // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 634 | + // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 635 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 636 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 637 | + $args[1] = $args[0]; |
|
| 638 | + $args[0] = $filtre; |
|
| 639 | + return image_graver(image_filtrer($args)); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + $f = chercher_filtre($filtre); |
|
| 643 | + if (!$f) { |
|
| 644 | + return $defaut; |
|
| 645 | + } |
|
| 646 | + array_shift($args); // enlever $arg |
|
| 647 | + array_shift($args); // enlever $filtre |
|
| 648 | + return $f($arg, ...$args); |
|
| 649 | 649 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * Code PHP compilé de la boucle |
| 33 | 33 | **/ |
| 34 | 34 | function boucle_DEFAUT_dist($id_boucle, &$boucles) { |
| 35 | - return calculer_boucle($id_boucle, $boucles); |
|
| 35 | + return calculer_boucle($id_boucle, $boucles); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * Code PHP compilé de la boucle |
| 52 | 52 | **/ |
| 53 | 53 | function boucle_BOUCLE_dist($id_boucle, &$boucles) { |
| 54 | - return calculer_boucle($id_boucle, $boucles); |
|
| 54 | + return calculer_boucle($id_boucle, $boucles); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -81,30 +81,30 @@ discard block |
||
| 81 | 81 | * Code PHP compilé de la boucle |
| 82 | 82 | **/ |
| 83 | 83 | function boucle_HIERARCHIE_dist($id_boucle, &$boucles) { |
| 84 | - $boucle = &$boucles[$id_boucle]; |
|
| 85 | - $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 84 | + $boucle = &$boucles[$id_boucle]; |
|
| 85 | + $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 86 | 86 | |
| 87 | - // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
|
| 88 | - // sauf en presence du critere {tout} (vu par phraser_html) |
|
| 89 | - // ou {id_article} qui positionne aussi le {tout} |
|
| 87 | + // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
|
| 88 | + // sauf en presence du critere {tout} (vu par phraser_html) |
|
| 89 | + // ou {id_article} qui positionne aussi le {tout} |
|
| 90 | 90 | |
| 91 | - $boucle->hierarchie = 'if (!($id_rubrique = intval(' |
|
| 92 | - . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles) |
|
| 93 | - . ")))\n\t\treturn '';\n\t" |
|
| 94 | - . "include_spip('inc/rubriques');\n\t" |
|
| 95 | - . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
|
| 96 | - . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
|
| 97 | - . ");\n\t" |
|
| 98 | - . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 91 | + $boucle->hierarchie = 'if (!($id_rubrique = intval(' |
|
| 92 | + . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles) |
|
| 93 | + . ")))\n\t\treturn '';\n\t" |
|
| 94 | + . "include_spip('inc/rubriques');\n\t" |
|
| 95 | + . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
|
| 96 | + . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
|
| 97 | + . ");\n\t" |
|
| 98 | + . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 99 | 99 | |
| 100 | - $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
|
| 100 | + $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
|
| 101 | 101 | |
| 102 | - $order = "FIELD($id_table, \$hierarchie)"; |
|
| 103 | - if (!isset($boucle->default_order[0]) or $boucle->default_order[0] != ' DESC') { |
|
| 104 | - $boucle->default_order[] = "\"$order\""; |
|
| 105 | - } else { |
|
| 106 | - $boucle->default_order[0] = "\"$order DESC\""; |
|
| 107 | - } |
|
| 102 | + $order = "FIELD($id_table, \$hierarchie)"; |
|
| 103 | + if (!isset($boucle->default_order[0]) or $boucle->default_order[0] != ' DESC') { |
|
| 104 | + $boucle->default_order[] = "\"$order\""; |
|
| 105 | + } else { |
|
| 106 | + $boucle->default_order[0] = "\"$order DESC\""; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - return calculer_boucle($id_boucle, $boucles); |
|
| 109 | + return calculer_boucle($id_boucle, $boucles); |
|
| 110 | 110 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | **/ |
| 83 | 83 | function boucle_HIERARCHIE_dist($id_boucle, &$boucles) { |
| 84 | 84 | $boucle = &$boucles[$id_boucle]; |
| 85 | - $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 85 | + $id_table = $boucle->id_table.'.id_rubrique'; |
|
| 86 | 86 | |
| 87 | 87 | // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
| 88 | 88 | // sauf en presence du critere {tout} (vu par phraser_html) |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
| 96 | 96 | . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
| 97 | 97 | . ");\n\t" |
| 98 | - . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 98 | + . 'if (!$hierarchie) return "";'."\n\t"; |
|
| 99 | 99 | |
| 100 | 100 | $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
| 101 | 101 | |
@@ -18,12 +18,12 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][21676] = [ |
| 26 | - ['ranger_cache_gd2'], |
|
| 26 | + ['ranger_cache_gd2'], |
|
| 27 | 27 | ]; |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -32,30 +32,30 @@ discard block |
||
| 32 | 32 | * https://core.spip.net/issues/3277 |
| 33 | 33 | */ |
| 34 | 34 | function ranger_cache_gd2() { |
| 35 | - spip_log('ranger_cache_gd2'); |
|
| 36 | - $base = _DIR_VAR . 'cache-gd2/'; |
|
| 37 | - if (is_dir($base) and is_readable($base)) { |
|
| 38 | - if ($dir = opendir($base)) { |
|
| 39 | - while (($f = readdir($dir)) !== false) { |
|
| 40 | - if ( |
|
| 41 | - !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | - and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
|
| 43 | - ) { |
|
| 44 | - $sub = substr($f, 0, 2); |
|
| 45 | - $sub = sous_repertoire($base, $sub); |
|
| 46 | - @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | - @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 48 | - } |
|
| 49 | - if (time() >= _TIME_OUT) { |
|
| 50 | - return; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 35 | + spip_log('ranger_cache_gd2'); |
|
| 36 | + $base = _DIR_VAR . 'cache-gd2/'; |
|
| 37 | + if (is_dir($base) and is_readable($base)) { |
|
| 38 | + if ($dir = opendir($base)) { |
|
| 39 | + while (($f = readdir($dir)) !== false) { |
|
| 40 | + if ( |
|
| 41 | + !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | + and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
|
| 43 | + ) { |
|
| 44 | + $sub = substr($f, 0, 2); |
|
| 45 | + $sub = sous_repertoire($base, $sub); |
|
| 46 | + @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | + @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 48 | + } |
|
| 49 | + if (time() >= _TIME_OUT) { |
|
| 50 | + return; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | $GLOBALS['maj'][21742] = [ |
| 59 | - ['sql_alter', "TABLE spip_articles CHANGE url_site url_site text DEFAULT '' NOT NULL"], |
|
| 60 | - ['sql_alter', "TABLE spip_articles CHANGE virtuel virtuel text DEFAULT '' NOT NULL"], |
|
| 59 | + ['sql_alter', "TABLE spip_articles CHANGE url_site url_site text DEFAULT '' NOT NULL"], |
|
| 60 | + ['sql_alter', "TABLE spip_articles CHANGE virtuel virtuel text DEFAULT '' NOT NULL"], |
|
| 61 | 61 | ]; |
@@ -33,18 +33,18 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | function ranger_cache_gd2() { |
| 35 | 35 | spip_log('ranger_cache_gd2'); |
| 36 | - $base = _DIR_VAR . 'cache-gd2/'; |
|
| 36 | + $base = _DIR_VAR.'cache-gd2/'; |
|
| 37 | 37 | if (is_dir($base) and is_readable($base)) { |
| 38 | 38 | if ($dir = opendir($base)) { |
| 39 | 39 | while (($f = readdir($dir)) !== false) { |
| 40 | 40 | if ( |
| 41 | - !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 41 | + !is_dir($base.$f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | 42 | and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
| 43 | 43 | ) { |
| 44 | 44 | $sub = substr($f, 0, 2); |
| 45 | 45 | $sub = sous_repertoire($base, $sub); |
| 46 | - @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | - @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 46 | + @rename($base.$f, $sub.substr($f, 2)); |
|
| 47 | + @unlink($base.$f); // au cas ou le rename a foire (collision) |
|
| 48 | 48 | } |
| 49 | 49 | if (time() >= _TIME_OUT) { |
| 50 | 50 | return; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('base/medias'); |
@@ -27,27 +27,27 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | // http://archives.rezo.net/archives/spip-zone.mbox/C6RZKNBUNJYN42IOEOC4QKVCA233AMLI/ |
| 29 | 29 | $GLOBALS['maj'][13833] = [ |
| 30 | - ['sql_alter', 'TABLE spip_documents_liens ADD INDEX objet(id_objet,objet)'] |
|
| 30 | + ['sql_alter', 'TABLE spip_documents_liens ADD INDEX objet(id_objet,objet)'] |
|
| 31 | 31 | ]; |
| 32 | 32 | |
| 33 | 33 | // 2.1 |
| 34 | 34 | |
| 35 | 35 | $GLOBALS['maj'][13904] = [ |
| 36 | - ['sql_alter', "TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"], |
|
| 37 | - [ |
|
| 38 | - 'sql_update', |
|
| 39 | - 'spip_auteurs', |
|
| 40 | - ['webmestre' => "'oui'"], |
|
| 41 | - sql_in('id_auteur', defined('_ID_WEBMESTRES') ? explode( |
|
| 42 | - ':', |
|
| 43 | - _ID_WEBMESTRES |
|
| 44 | - ) : (autoriser('configurer') ? [$GLOBALS['visiteur_session']['id_auteur']] : [0])) |
|
| 45 | - ] // le webmestre est celui qui fait l'upgrade si rien de defini |
|
| 36 | + ['sql_alter', "TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"], |
|
| 37 | + [ |
|
| 38 | + 'sql_update', |
|
| 39 | + 'spip_auteurs', |
|
| 40 | + ['webmestre' => "'oui'"], |
|
| 41 | + sql_in('id_auteur', defined('_ID_WEBMESTRES') ? explode( |
|
| 42 | + ':', |
|
| 43 | + _ID_WEBMESTRES |
|
| 44 | + ) : (autoriser('configurer') ? [$GLOBALS['visiteur_session']['id_auteur']] : [0])) |
|
| 45 | + ] // le webmestre est celui qui fait l'upgrade si rien de defini |
|
| 46 | 46 | ]; |
| 47 | 47 | |
| 48 | 48 | // sites plantes en mode "'su" au lieu de "sus" |
| 49 | 49 | $GLOBALS['maj'][13929] = [ |
| 50 | - ['sql_update', 'spip_syndic', ['syndication' => "'sus'"], "syndication LIKE '\\'%'"] |
|
| 50 | + ['sql_update', 'spip_syndic', ['syndication' => "'sus'"], "syndication LIKE '\\'%'"] |
|
| 51 | 51 | ]; |
| 52 | 52 | |
| 53 | 53 | // Types de fichiers m4a/m4b/m4p/m4u/m4v/dv |
@@ -61,24 +61,24 @@ discard block |
||
| 61 | 61 | // La version 14588 etait une mauvaise piste: |
| 62 | 62 | // Retour en arriere pour ceux qui l'ont subi, ne rien faire sinon |
| 63 | 63 | if (@$GLOBALS['meta']['version_installee'] >= 14588) { |
| 64 | - // "mode" est un mot-cle d'Oracle |
|
| 65 | - $GLOBALS['maj'][14588] = [ |
|
| 66 | - ['sql_alter', 'TABLE spip_documents DROP INDEX mode'], |
|
| 67 | - [ |
|
| 68 | - 'sql_alter', |
|
| 69 | - "TABLE spip_documents CHANGE mode genre ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 70 | - ], |
|
| 71 | - ['sql_alter', 'TABLE spip_documents ADD INDEX genre(genre)'] |
|
| 72 | - ]; |
|
| 73 | - // solution moins intrusive au pb de mot-cle d'Oracle, retour avant 14588 |
|
| 74 | - $GLOBALS['maj'][14598] = [ |
|
| 75 | - ['sql_alter', 'TABLE spip_documents DROP INDEX genre'], |
|
| 76 | - [ |
|
| 77 | - 'sql_alter', |
|
| 78 | - "TABLE spip_documents CHANGE genre mode ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 79 | - ], |
|
| 80 | - ['sql_alter', 'TABLE spip_documents ADD INDEX mode(mode)'] |
|
| 81 | - ]; |
|
| 64 | + // "mode" est un mot-cle d'Oracle |
|
| 65 | + $GLOBALS['maj'][14588] = [ |
|
| 66 | + ['sql_alter', 'TABLE spip_documents DROP INDEX mode'], |
|
| 67 | + [ |
|
| 68 | + 'sql_alter', |
|
| 69 | + "TABLE spip_documents CHANGE mode genre ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 70 | + ], |
|
| 71 | + ['sql_alter', 'TABLE spip_documents ADD INDEX genre(genre)'] |
|
| 72 | + ]; |
|
| 73 | + // solution moins intrusive au pb de mot-cle d'Oracle, retour avant 14588 |
|
| 74 | + $GLOBALS['maj'][14598] = [ |
|
| 75 | + ['sql_alter', 'TABLE spip_documents DROP INDEX genre'], |
|
| 76 | + [ |
|
| 77 | + 'sql_alter', |
|
| 78 | + "TABLE spip_documents CHANGE genre mode ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 79 | + ], |
|
| 80 | + ['sql_alter', 'TABLE spip_documents ADD INDEX mode(mode)'] |
|
| 81 | + ]; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // Restauration correcte des types mime des fichiers Ogg |
@@ -18,10 +18,10 @@ |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][23375] = [ |
| 26 | - ['sql_alter', 'TABLE spip_auteurs CHANGE prefs prefs text'], |
|
| 26 | + ['sql_alter', 'TABLE spip_auteurs CHANGE prefs prefs text'], |
|
| 27 | 27 | ]; |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @package SPIP\Core\SQL\Upgrade |
| 21 | 21 | **/ |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
@@ -35,49 +35,49 @@ discard block |
||
| 35 | 35 | **/ |
| 36 | 36 | function maj_timestamp_mysql($tables = null) { |
| 37 | 37 | |
| 38 | - include_spip('base/dump'); |
|
| 39 | - if (is_null($tables)) { |
|
| 40 | - $tables = base_lister_toutes_tables(); |
|
| 41 | - } elseif (is_string($tables)) { |
|
| 42 | - $tables = [$tables]; |
|
| 43 | - } elseif (!is_array($tables)) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 38 | + include_spip('base/dump'); |
|
| 39 | + if (is_null($tables)) { |
|
| 40 | + $tables = base_lister_toutes_tables(); |
|
| 41 | + } elseif (is_string($tables)) { |
|
| 42 | + $tables = [$tables]; |
|
| 43 | + } elseif (!is_array($tables)) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - // rien a faire si base non mysql |
|
| 48 | - if (strncmp($GLOBALS['connexions'][0]['type'], 'mysql', 5) !== 0) { |
|
| 49 | - return; |
|
| 50 | - } |
|
| 47 | + // rien a faire si base non mysql |
|
| 48 | + if (strncmp($GLOBALS['connexions'][0]['type'], 'mysql', 5) !== 0) { |
|
| 49 | + return; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 53 | - // forcer le vidage de cache |
|
| 54 | - $trouver_table(''); |
|
| 52 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 53 | + // forcer le vidage de cache |
|
| 54 | + $trouver_table(''); |
|
| 55 | 55 | |
| 56 | - foreach ($tables as $table) { |
|
| 57 | - if (time() >= _TIME_OUT) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - if ($desc = $trouver_table($table)) { |
|
| 61 | - $fields_corrected = _mysql_remplacements_definitions_table($desc['field']); |
|
| 62 | - $d = array_diff($desc['field'], $fields_corrected); |
|
| 63 | - if ($d) { |
|
| 64 | - spip_log("Table $table TIMESTAMP incorrect", 'maj'); |
|
| 65 | - foreach ($desc['field'] as $field => $type) { |
|
| 66 | - if ($desc['field'][$field] !== $fields_corrected[$field]) { |
|
| 67 | - spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 68 | - sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
|
| 69 | - $trouver_table(''); |
|
| 70 | - $new_desc = $trouver_table($table); |
|
| 71 | - spip_log( |
|
| 72 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 73 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 74 | - ); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - } |
|
| 56 | + foreach ($tables as $table) { |
|
| 57 | + if (time() >= _TIME_OUT) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + if ($desc = $trouver_table($table)) { |
|
| 61 | + $fields_corrected = _mysql_remplacements_definitions_table($desc['field']); |
|
| 62 | + $d = array_diff($desc['field'], $fields_corrected); |
|
| 63 | + if ($d) { |
|
| 64 | + spip_log("Table $table TIMESTAMP incorrect", 'maj'); |
|
| 65 | + foreach ($desc['field'] as $field => $type) { |
|
| 66 | + if ($desc['field'][$field] !== $fields_corrected[$field]) { |
|
| 67 | + spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 68 | + sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
|
| 69 | + $trouver_table(''); |
|
| 70 | + $new_desc = $trouver_table($table); |
|
| 71 | + spip_log( |
|
| 72 | + "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 73 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // forcer le vidage de cache |
|
| 82 | - $trouver_table(''); |
|
| 81 | + // forcer le vidage de cache |
|
| 82 | + $trouver_table(''); |
|
| 83 | 83 | } |
@@ -64,13 +64,13 @@ |
||
| 64 | 64 | spip_log("Table $table TIMESTAMP incorrect", 'maj'); |
| 65 | 65 | foreach ($desc['field'] as $field => $type) { |
| 66 | 66 | if ($desc['field'][$field] !== $fields_corrected[$field]) { |
| 67 | - spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 68 | - sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
|
| 67 | + spip_log("Adaptation TIMESTAMP table $table", 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 68 | + sql_alter("table $table change $field $field ".$fields_corrected[$field]); |
|
| 69 | 69 | $trouver_table(''); |
| 70 | 70 | $new_desc = $trouver_table($table); |
| 71 | 71 | spip_log( |
| 72 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 73 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 72 | + "Apres conversion $table : ".var_export($new_desc['field'], true), |
|
| 73 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 74 | 74 | ); |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('maj/legacy/v30'); |