Completed
Push — master ( 3ef74e...08981b )
by cam
04:31
created
ecrire/public/phraser_html.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -48,19 +48,19 @@  discard block
 block discarded – undo
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
 // https://code.spip.net/@phraser_inclure
66 66
 function phraser_inclure($texte, $ligne, $result) {
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
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, $match[0]);
220 220
 		// texte après la balise
221 221
 		$suite = substr($texte, $p + strlen($match[0]));
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 			$collecte[] = $champ;
362 362
 			$args = ltrim($regs[count($regs) - 1]);
363 363
 		} else {
364
-			if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)) {
364
+			if (!preg_match("/".NOM_DE_CHAMP."([{|])/", $arg, $r)) {
365 365
 				// 0 est un aveu d'impuissance. A completer
366 366
 				$arg = phraser_champs_exterieurs($arg, 0, $sep, $result);
367 367
 
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) {
447 447
 	$res = array();
448 448
 	while (($p = strpos($texte, "%$sep")) !== false) {
449
-		if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) {
449
+		if (!preg_match(',^%'.preg_quote($sep).'([0-9]+)@,', substr($texte, $p), $m)) {
450 450
 			break;
451 451
 		}
452 452
 		$debut = substr($texte, 0, $p);
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 					// une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"}
615 615
 					if (preg_match(',^(["\'])(.*)\1$,', $m[4])) {
616 616
 						$c = null;
617
-						eval('$c = ' . $m[4] . ';');
617
+						eval('$c = '.$m[4].';');
618 618
 						if (isset($c)) {
619 619
 							$m[4] = $c;
620 620
 						}
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
 
693 693
 					if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) {
694 694
 						$crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', '');
695
-					} elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC .
695
+					} elseif (preg_match(',^([!]?)('.CHAMP_SQL_PLUS_FONC.
696 696
 						')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) {
697 697
 						$a2 = trim($m[8]);
698 698
 						if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) {
@@ -702,8 +702,8 @@  discard block
 block discarded – undo
702 702
 							(($m[2] == 'lang_select') ? $m[2] : $m[7]),
703 703
 							$m[6], $m[5]);
704 704
 						$crit->exclus = $m[1];
705
-					} elseif (preg_match("/^([!]?)\s*(" .
706
-						CHAMP_SQL_PLUS_FONC .
705
+					} elseif (preg_match("/^([!]?)\s*(".
706
+						CHAMP_SQL_PLUS_FONC.
707 707
 						")\s*(\??)(.*)$/is", $param, $m)) {
708 708
 						// contient aussi les comparaisons implicites !
709 709
 						// Comme ci-dessus: 
@@ -802,9 +802,9 @@  discard block
 block discarded – undo
802 802
 	$current_pos = 0;
803 803
 	while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) {
804 804
 		$current_pos = $pos_boucle + 1;
805
-		$pos_parent = strpos($texte,'(', $pos_boucle);
805
+		$pos_parent = strpos($texte, '(', $pos_boucle);
806 806
 		if ($pos_parent === false
807
-		  or !$id_boucle = trim(substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE)))
807
+		  or !$id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE)))
808 808
 			or !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) {
809 809
 
810 810
 			$result = new Boucle;
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
 
814 814
 			// un id_boucle pour l'affichage de l'erreur
815 815
 			if (!$id_boucle) {
816
-				$id_boucle = substr($texte,$pos_boucle + strlen(BALISE_BOUCLE), 15);
816
+				$id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15);
817 817
 			}
818 818
 			$result->id_boucle = $id_boucle;
819 819
 			$err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle));
@@ -834,7 +834,7 @@  discard block
 block discarded – undo
834 834
 			];
835 835
 
836 836
 			// trouver sa position de depart reelle : au <B_ ou au <BB_
837
-			$precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>';
837
+			$precond_boucle = BALISE_PRECOND_BOUCLE.$id_boucle.'>';
838 838
 			$pos_precond = strpos($texte, $precond_boucle);
839 839
 			if ($pos_precond !== false and $pos_precond < $boucle['debut_boucle']) {
840 840
 				$boucle['debut_boucle'] = $pos_precond;
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 				$boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle);
843 843
 			}
844 844
 
845
-			$preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>';
845
+			$preaff_boucle = BALISE_PREAFF_BOUCLE.$id_boucle.'>';
846 846
 			$pos_preaff = strpos($texte, $preaff_boucle);
847 847
 			if ($pos_preaff !== false and $pos_preaff < $boucle['debut_boucle']) {
848 848
 				$boucle['debut_boucle'] = $pos_preaff;
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 
886 886
 			$pos_avant = $boucle['pos_precond_inside'];
887 887
 			$result->avant = substr($texte, $pos_avant, $pos_boucle - $pos_avant);
888
-			$ligne_avant = $ligne +  public_compte_ligne($texte,0, $pos_avant);
888
+			$ligne_avant = $ligne + public_compte_ligne($texte, 0, $pos_avant);
889 889
 		}
890 890
 
891 891
 		// Regarder si on a une partie inconditionnelle avant <BB_xxx>
@@ -895,7 +895,7 @@  discard block
 block discarded – undo
895 895
 
896 896
 			$pos_preaff = $boucle['pos_preaff_inside'];
897 897
 			$result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff);
898
-			$ligne_preaff = $ligne +  public_compte_ligne($texte,0, $pos_preaff);
898
+			$ligne_preaff = $ligne + public_compte_ligne($texte, 0, $pos_preaff);
899 899
 		}
900 900
 
901 901
 		$debut = substr($texte, 0, $boucle['debut_boucle']);
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
 			$milieu = substr($milieu, 1);
954 954
 			$pos_boucle += 1;
955 955
 
956
-			$fin_boucle = BALISE_FIN_BOUCLE . $id_boucle . ">";
956
+			$fin_boucle = BALISE_FIN_BOUCLE.$id_boucle.">";
957 957
 			$pos_fin = strpos($milieu, $fin_boucle);
958 958
 			if ($pos_fin === false) {
959 959
 				$err_b = array(
@@ -974,14 +974,14 @@  discard block
 block discarded – undo
974 974
 		//
975 975
 		// 1. Recuperer la partie conditionnelle apres
976 976
 		//
977
-		$apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . ">";
977
+		$apres_boucle = BALISE_POSTCOND_BOUCLE.$id_boucle.">";
978 978
 		$pos_apres = strpos($suite, $apres_boucle);
979 979
 		if ($pos_apres !== false) {
980 980
 			$result->apres = substr($suite, 0, $pos_apres);
981 981
 			$pos_apres += strlen($apres_boucle);
982 982
 			$suite = substr($suite, $pos_apres);
983 983
 			$ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_apres);
984
-			$pos_boucle += $pos_apres ;
984
+			$pos_boucle += $pos_apres;
985 985
 		}
986 986
 
987 987
 
@@ -989,7 +989,7 @@  discard block
 block discarded – undo
989 989
 		// 2. Recuperer la partie alternative
990 990
 		//
991 991
 		$ligne_altern = $ligne_suite;
992
-		$altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . ">";
992
+		$altern_boucle = BALISE_ALT_BOUCLE.$id_boucle.">";
993 993
 		$pos_altern = strpos($suite, $altern_boucle);
994 994
 		if ($pos_altern !== false) {
995 995
 			$result->altern = substr($suite, 0, $pos_altern);
@@ -1003,14 +1003,14 @@  discard block
 block discarded – undo
1003 1003
 		// 3. Recuperer la partie footer non alternative
1004 1004
 		//
1005 1005
 		$ligne_postaff = $ligne_suite;
1006
-		$postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . ">";
1006
+		$postaff_boucle = BALISE_POSTAFF_BOUCLE.$id_boucle.">";
1007 1007
 		$pos_postaff = strpos($suite, $postaff_boucle);
1008 1008
 		if ($pos_postaff !== false) {
1009 1009
 			$result->postaff = substr($suite, 0, $pos_postaff);
1010 1010
 			$pos_postaff += strlen($postaff_boucle);
1011 1011
 			$suite = substr($suite, $pos_postaff);
1012 1012
 			$ligne_suite += public_compte_ligne($texte, $pos_boucle, $pos_postaff);
1013
-			$pos_boucle += $pos_postaff ;
1013
+			$pos_boucle += $pos_postaff;
1014 1014
 		}
1015 1015
 
1016 1016
 		$result->ligne = $ligne_preaff;
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
 		// reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre
1046 1046
 		// ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle
1047 1047
 		// si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite
1048
-		if (empty($boucles[$id_boucle])){
1048
+		if (empty($boucles[$id_boucle])) {
1049 1049
 			$boucles[$id_boucle] = null;
1050 1050
 		}
1051 1051
 		$result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff);
Please login to merge, or discard this patch.