@@ -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 | /** |
@@ -32,67 +32,67 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | // Cas d'une page contenant du PHP : |
| 34 | 34 | if (empty($page['process_ins']) or $page['process_ins'] != 'html') { |
| 35 | - include_spip('inc/lang'); |
|
| 35 | + include_spip('inc/lang'); |
|
| 36 | 36 | |
| 37 | - // restaurer l'etat des notes avant calcul |
|
| 38 | - if ( |
|
| 39 | - isset($page['notes']) |
|
| 40 | - and $page['notes'] |
|
| 41 | - and $notes = charger_fonction('notes', 'inc', true) |
|
| 42 | - ) { |
|
| 43 | - $notes($page['notes'], 'restaurer_etat'); |
|
| 44 | - } |
|
| 45 | - ob_start(); |
|
| 46 | - if (strpos($page['texte'], '?xml') !== false) { |
|
| 47 | - $page['texte'] = str_replace('<' . '?xml', "<\1?xml", $page['texte']); |
|
| 48 | - } |
|
| 37 | + // restaurer l'etat des notes avant calcul |
|
| 38 | + if ( |
|
| 39 | + isset($page['notes']) |
|
| 40 | + and $page['notes'] |
|
| 41 | + and $notes = charger_fonction('notes', 'inc', true) |
|
| 42 | + ) { |
|
| 43 | + $notes($page['notes'], 'restaurer_etat'); |
|
| 44 | + } |
|
| 45 | + ob_start(); |
|
| 46 | + if (strpos($page['texte'], '?xml') !== false) { |
|
| 47 | + $page['texte'] = str_replace('<' . '?xml', "<\1?xml", $page['texte']); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - try { |
|
| 51 | - $res = eval('?' . '>' . $page['texte']); |
|
| 52 | - // error catching 5.2<=PHP<7 |
|
| 53 | - if ( |
|
| 54 | - $res === false |
|
| 55 | - and function_exists('error_get_last') |
|
| 56 | - and ($erreur = error_get_last()) |
|
| 57 | - ) { |
|
| 58 | - $code = $page['texte']; |
|
| 59 | - $GLOBALS['numero_ligne_php'] = 1; |
|
| 60 | - if (!function_exists('numerote_ligne_php')) { |
|
| 61 | - function numerote_ligne_php($match) { |
|
| 62 | - $GLOBALS['numero_ligne_php']++; |
|
| 63 | - return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 67 | - $code = trim(highlight_string($code, true)); |
|
| 68 | - erreur_squelette('L' . $erreur['line'] . ': ' . $erreur['message'] . '<br />' . $code, [$page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']]); |
|
| 69 | - $page['texte'] = '<!-- Erreur -->'; |
|
| 70 | - } |
|
| 71 | - else { |
|
| 72 | - $page['texte'] = ob_get_contents(); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - catch (Exception $e) { |
|
| 76 | - $code = $page['texte']; |
|
| 77 | - $GLOBALS['numero_ligne_php'] = 1; |
|
| 78 | - if (!function_exists('numerote_ligne_php')) { |
|
| 79 | - function numerote_ligne_php($match) { |
|
| 80 | - $GLOBALS['numero_ligne_php']++; |
|
| 81 | - return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 85 | - $code = trim(highlight_string($code, true)); |
|
| 86 | - erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]); |
|
| 87 | - $page['texte'] = '<!-- Erreur -->'; |
|
| 88 | - } |
|
| 89 | - ob_end_clean(); |
|
| 50 | + try { |
|
| 51 | + $res = eval('?' . '>' . $page['texte']); |
|
| 52 | + // error catching 5.2<=PHP<7 |
|
| 53 | + if ( |
|
| 54 | + $res === false |
|
| 55 | + and function_exists('error_get_last') |
|
| 56 | + and ($erreur = error_get_last()) |
|
| 57 | + ) { |
|
| 58 | + $code = $page['texte']; |
|
| 59 | + $GLOBALS['numero_ligne_php'] = 1; |
|
| 60 | + if (!function_exists('numerote_ligne_php')) { |
|
| 61 | + function numerote_ligne_php($match) { |
|
| 62 | + $GLOBALS['numero_ligne_php']++; |
|
| 63 | + return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 67 | + $code = trim(highlight_string($code, true)); |
|
| 68 | + erreur_squelette('L' . $erreur['line'] . ': ' . $erreur['message'] . '<br />' . $code, [$page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']]); |
|
| 69 | + $page['texte'] = '<!-- Erreur -->'; |
|
| 70 | + } |
|
| 71 | + else { |
|
| 72 | + $page['texte'] = ob_get_contents(); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + catch (Exception $e) { |
|
| 76 | + $code = $page['texte']; |
|
| 77 | + $GLOBALS['numero_ligne_php'] = 1; |
|
| 78 | + if (!function_exists('numerote_ligne_php')) { |
|
| 79 | + function numerote_ligne_php($match) { |
|
| 80 | + $GLOBALS['numero_ligne_php']++; |
|
| 81 | + return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 85 | + $code = trim(highlight_string($code, true)); |
|
| 86 | + erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]); |
|
| 87 | + $page['texte'] = '<!-- Erreur -->'; |
|
| 88 | + } |
|
| 89 | + ob_end_clean(); |
|
| 90 | 90 | |
| 91 | - $page['process_ins'] = 'html'; |
|
| 91 | + $page['process_ins'] = 'html'; |
|
| 92 | 92 | |
| 93 | - if (strpos($page['texte'], '?xml') !== false) { |
|
| 94 | - $page['texte'] = str_replace("<\1?xml", '<' . '?xml', $page['texte']); |
|
| 95 | - } |
|
| 93 | + if (strpos($page['texte'], '?xml') !== false) { |
|
| 94 | + $page['texte'] = str_replace("<\1?xml", '<' . '?xml', $page['texte']); |
|
| 95 | + } |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | page_base_href($page['texte']); |
@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | ob_start(); |
| 46 | 46 | if (strpos($page['texte'], '?xml') !== false) { |
| 47 | - $page['texte'] = str_replace('<' . '?xml', "<\1?xml", $page['texte']); |
|
| 47 | + $page['texte'] = str_replace('<'.'?xml', "<\1?xml", $page['texte']); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | try { |
| 51 | - $res = eval('?' . '>' . $page['texte']); |
|
| 51 | + $res = eval('?'.'>'.$page['texte']); |
|
| 52 | 52 | // error catching 5.2<=PHP<7 |
| 53 | 53 | if ( |
| 54 | 54 | $res === false |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | if (!function_exists('numerote_ligne_php')) { |
| 61 | 61 | function numerote_ligne_php($match) { |
| 62 | 62 | $GLOBALS['numero_ligne_php']++; |
| 63 | - return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 63 | + return "\n/*".str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT).'*/'; |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | - $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 66 | + $code = '/*001*/'.preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 67 | 67 | $code = trim(highlight_string($code, true)); |
| 68 | - erreur_squelette('L' . $erreur['line'] . ': ' . $erreur['message'] . '<br />' . $code, [$page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']]); |
|
| 68 | + erreur_squelette('L'.$erreur['line'].': '.$erreur['message'].'<br />'.$code, [$page['source'], '', $erreur['file'], '', $GLOBALS['spip_lang']]); |
|
| 69 | 69 | $page['texte'] = '<!-- Erreur -->'; |
| 70 | 70 | } |
| 71 | 71 | else { |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | if (!function_exists('numerote_ligne_php')) { |
| 79 | 79 | function numerote_ligne_php($match) { |
| 80 | 80 | $GLOBALS['numero_ligne_php']++; |
| 81 | - return "\n/*" . str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT) . '*/'; |
|
| 81 | + return "\n/*".str_pad($GLOBALS['numero_ligne_php'], 3, '0', STR_PAD_LEFT).'*/'; |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | - $code = '/*001*/' . preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 84 | + $code = '/*001*/'.preg_replace_callback(",\n,", 'numerote_ligne_php', $code); |
|
| 85 | 85 | $code = trim(highlight_string($code, true)); |
| 86 | - erreur_squelette('L' . $e->getLine() . ': ' . $e->getMessage() . '<br />' . $code, [$page['source'],'',$e->getFile(),'',$GLOBALS['spip_lang']]); |
|
| 86 | + erreur_squelette('L'.$e->getLine().': '.$e->getMessage().'<br />'.$code, [$page['source'], '', $e->getFile(), '', $GLOBALS['spip_lang']]); |
|
| 87 | 87 | $page['texte'] = '<!-- Erreur -->'; |
| 88 | 88 | } |
| 89 | 89 | ob_end_clean(); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | $page['process_ins'] = 'html'; |
| 92 | 92 | |
| 93 | 93 | if (strpos($page['texte'], '?xml') !== false) { |
| 94 | - $page['texte'] = str_replace("<\1?xml", '<' . '?xml', $page['texte']); |
|
| 94 | + $page['texte'] = str_replace("<\1?xml", '<'.'?xml', $page['texte']); |
|
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
@@ -67,12 +67,10 @@ |
||
| 67 | 67 | $code = trim(highlight_string($code, true)); |
| 68 | 68 | erreur_squelette('L' . $erreur['line'] . ': ' . $erreur['message'] . '<br />' . $code, [$page['source'],'',$erreur['file'],'',$GLOBALS['spip_lang']]); |
| 69 | 69 | $page['texte'] = '<!-- Erreur -->'; |
| 70 | - } |
|
| 71 | - else { |
|
| 70 | + } else { |
|
| 72 | 71 | $page['texte'] = ob_get_contents(); |
| 73 | 72 | } |
| 74 | - } |
|
| 75 | - catch (Exception $e) { |
|
| 73 | + } catch (Exception $e) { |
|
| 76 | 74 | $code = $page['texte']; |
| 77 | 75 | $GLOBALS['numero_ligne_php'] = 1; |
| 78 | 76 | if (!function_exists('numerote_ligne_php')) { |
@@ -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); |
@@ -465,7 +465,7 @@ discard block |
||
| 465 | 465 | case 'sinum ': |
| 466 | 466 | return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
| 467 | 467 | default: |
| 468 | - return $champ . $senstri; |
|
| 468 | + return $champ.$senstri; |
|
| 469 | 469 | } |
| 470 | 470 | } |
| 471 | 471 | |
@@ -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 | } |
@@ -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 | |
@@ -52,75 +52,75 @@ discard block |
||
| 52 | 52 | * Introduction calculée |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 55 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | - if (strlen($descriptif)) { |
|
| 57 | - return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - // De preference ce qui est marque <intro>...</intro> |
|
| 61 | - $intro = ''; |
|
| 62 | - $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 63 | - while ($fin = strpos($texte, '</intro>')) { |
|
| 64 | - $zone = substr($texte, 0, $fin); |
|
| 65 | - $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 66 | - if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 67 | - $zone = substr($zone, $deb + 7); |
|
| 68 | - } |
|
| 69 | - $intro .= $zone; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | - // qui inclus raccourcis et modeles |
|
| 74 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | - // des surcharges et enrichissement de propre |
|
| 77 | - // couper doit se faire apres propre |
|
| 78 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | - |
|
| 80 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | - // large et en se mefiant des tableaux #1323 |
|
| 82 | - |
|
| 83 | - if (strlen($intro)) { |
|
| 84 | - $texte = $intro; |
|
| 85 | - } else { |
|
| 86 | - if ( |
|
| 87 | - strpos("\n" . $texte, "\n|") === false |
|
| 88 | - and strlen($texte) > 2.5 * $longueur |
|
| 89 | - ) { |
|
| 90 | - if (strpos($texte, '<multi') !== false) { |
|
| 91 | - $texte = extraire_multi($texte); |
|
| 92 | - } |
|
| 93 | - $texte = couper($texte, 2 * $longueur); |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // ne pas tenir compte des notes |
|
| 98 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 99 | - $notes('', 'empiler'); |
|
| 100 | - } |
|
| 101 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 102 | - // dans l'introduction. |
|
| 103 | - $texte = supprime_img($texte, ''); |
|
| 104 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 105 | - |
|
| 106 | - if ($notes) { |
|
| 107 | - $notes('', 'depiler'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 111 | - $suite = _INTRODUCTION_SUITE; |
|
| 112 | - } |
|
| 113 | - $texte = couper($texte, $longueur, $suite); |
|
| 114 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 115 | - $texte = typo($texte, true, $connect, []); |
|
| 116 | - |
|
| 117 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 118 | - // une introduction a tojours un <p> |
|
| 119 | - if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 120 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $texte; |
|
| 55 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | + if (strlen($descriptif)) { |
|
| 57 | + return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + // De preference ce qui est marque <intro>...</intro> |
|
| 61 | + $intro = ''; |
|
| 62 | + $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 63 | + while ($fin = strpos($texte, '</intro>')) { |
|
| 64 | + $zone = substr($texte, 0, $fin); |
|
| 65 | + $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 66 | + if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 67 | + $zone = substr($zone, $deb + 7); |
|
| 68 | + } |
|
| 69 | + $intro .= $zone; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | + // qui inclus raccourcis et modeles |
|
| 74 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | + // des surcharges et enrichissement de propre |
|
| 77 | + // couper doit se faire apres propre |
|
| 78 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | + |
|
| 80 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | + // large et en se mefiant des tableaux #1323 |
|
| 82 | + |
|
| 83 | + if (strlen($intro)) { |
|
| 84 | + $texte = $intro; |
|
| 85 | + } else { |
|
| 86 | + if ( |
|
| 87 | + strpos("\n" . $texte, "\n|") === false |
|
| 88 | + and strlen($texte) > 2.5 * $longueur |
|
| 89 | + ) { |
|
| 90 | + if (strpos($texte, '<multi') !== false) { |
|
| 91 | + $texte = extraire_multi($texte); |
|
| 92 | + } |
|
| 93 | + $texte = couper($texte, 2 * $longueur); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // ne pas tenir compte des notes |
|
| 98 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 99 | + $notes('', 'empiler'); |
|
| 100 | + } |
|
| 101 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 102 | + // dans l'introduction. |
|
| 103 | + $texte = supprime_img($texte, ''); |
|
| 104 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 105 | + |
|
| 106 | + if ($notes) { |
|
| 107 | + $notes('', 'depiler'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 111 | + $suite = _INTRODUCTION_SUITE; |
|
| 112 | + } |
|
| 113 | + $texte = couper($texte, $longueur, $suite); |
|
| 114 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 115 | + $texte = typo($texte, true, $connect, []); |
|
| 116 | + |
|
| 117 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 118 | + // une introduction a tojours un <p> |
|
| 119 | + if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 120 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $texte; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | |
@@ -155,73 +155,73 @@ discard block |
||
| 155 | 155 | * Code HTML de la pagination |
| 156 | 156 | **/ |
| 157 | 157 | function filtre_pagination_dist( |
| 158 | - $total, |
|
| 159 | - $nom, |
|
| 160 | - $position, |
|
| 161 | - $pas, |
|
| 162 | - $liste = true, |
|
| 163 | - $modele = '', |
|
| 164 | - $connect = '', |
|
| 165 | - $env = [] |
|
| 158 | + $total, |
|
| 159 | + $nom, |
|
| 160 | + $position, |
|
| 161 | + $pas, |
|
| 162 | + $liste = true, |
|
| 163 | + $modele = '', |
|
| 164 | + $connect = '', |
|
| 165 | + $env = [] |
|
| 166 | 166 | ) { |
| 167 | - static $ancres = []; |
|
| 168 | - if ($pas < 1) { |
|
| 169 | - return ''; |
|
| 170 | - } |
|
| 171 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 173 | - |
|
| 174 | - // n'afficher l'ancre qu'une fois |
|
| 175 | - if (!isset($ancres[$ancre])) { |
|
| 176 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 177 | - } else { |
|
| 178 | - $bloc_ancre = ''; |
|
| 179 | - } |
|
| 180 | - // liste = false : on ne veut que l'ancre |
|
| 181 | - if (!$liste) { |
|
| 182 | - return $ancres[$ancre]; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - $self = (empty($env['self']) ? self() : $env['self']); |
|
| 186 | - $pagination = [ |
|
| 187 | - 'debut' => $debut, |
|
| 188 | - 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 189 | - 'total' => $total, |
|
| 190 | - 'position' => intval($position), |
|
| 191 | - 'pas' => $pas, |
|
| 192 | - 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 193 | - 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 194 | - 'ancre' => $ancre, |
|
| 195 | - 'bloc_ancre' => $bloc_ancre |
|
| 196 | - ]; |
|
| 197 | - if (is_array($env)) { |
|
| 198 | - $pagination = array_merge($env, $pagination); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // Pas de pagination |
|
| 202 | - if ($pagination['nombre_pages'] <= 1) { |
|
| 203 | - return ''; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($modele) { |
|
| 207 | - $pagination['type_pagination'] = $modele; |
|
| 208 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | - $modele = '_' . $modele; |
|
| 210 | - } |
|
| 211 | - else { |
|
| 212 | - $modele = ''; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 217 | - define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 218 | - } |
|
| 219 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 220 | - define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 167 | + static $ancres = []; |
|
| 168 | + if ($pas < 1) { |
|
| 169 | + return ''; |
|
| 170 | + } |
|
| 171 | + $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | + $debut = 'debut' . $nom; // 'debut_articles' |
|
| 173 | + |
|
| 174 | + // n'afficher l'ancre qu'une fois |
|
| 175 | + if (!isset($ancres[$ancre])) { |
|
| 176 | + $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 177 | + } else { |
|
| 178 | + $bloc_ancre = ''; |
|
| 179 | + } |
|
| 180 | + // liste = false : on ne veut que l'ancre |
|
| 181 | + if (!$liste) { |
|
| 182 | + return $ancres[$ancre]; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + $self = (empty($env['self']) ? self() : $env['self']); |
|
| 186 | + $pagination = [ |
|
| 187 | + 'debut' => $debut, |
|
| 188 | + 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 189 | + 'total' => $total, |
|
| 190 | + 'position' => intval($position), |
|
| 191 | + 'pas' => $pas, |
|
| 192 | + 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 193 | + 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 194 | + 'ancre' => $ancre, |
|
| 195 | + 'bloc_ancre' => $bloc_ancre |
|
| 196 | + ]; |
|
| 197 | + if (is_array($env)) { |
|
| 198 | + $pagination = array_merge($env, $pagination); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // Pas de pagination |
|
| 202 | + if ($pagination['nombre_pages'] <= 1) { |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($modele) { |
|
| 207 | + $pagination['type_pagination'] = $modele; |
|
| 208 | + if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | + $modele = '_' . $modele; |
|
| 210 | + } |
|
| 211 | + else { |
|
| 212 | + $modele = ''; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 217 | + define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 218 | + } |
|
| 219 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 220 | + define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
@@ -240,44 +240,44 @@ discard block |
||
| 240 | 240 | * Liste (première page, dernière page). |
| 241 | 241 | **/ |
| 242 | 242 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 243 | - if ($max <= 0 or $max >= $nombre) { |
|
| 244 | - return [1, $nombre]; |
|
| 245 | - } |
|
| 246 | - if ($max <= 1) { |
|
| 247 | - return [$courante, $courante]; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 251 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 252 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 253 | - |
|
| 254 | - return [$premiere, $derniere]; |
|
| 243 | + if ($max <= 0 or $max >= $nombre) { |
|
| 244 | + return [1, $nombre]; |
|
| 245 | + } |
|
| 246 | + if ($max <= 1) { |
|
| 247 | + return [$courante, $courante]; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 251 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 252 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 253 | + |
|
| 254 | + return [$premiere, $derniere]; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | function filtre_pagination_affiche_texte_lien_page_dist($type_pagination, $numero_page, $rang_item) { |
| 258 | - if ($numero_page === 'tous') { |
|
| 259 | - return '∞'; |
|
| 260 | - } |
|
| 261 | - if ($numero_page === 'prev') { |
|
| 262 | - return '<'; |
|
| 263 | - } |
|
| 264 | - if ($numero_page === 'next') { |
|
| 265 | - return '>'; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - switch ($type_pagination) { |
|
| 269 | - case 'resultats': |
|
| 270 | - return $rang_item + 1; // 1 11 21 31... |
|
| 271 | - case 'naturel': |
|
| 272 | - return $rang_item ? $rang_item : 1; // 1 10 20 30... |
|
| 273 | - case 'rang': |
|
| 274 | - return $rang_item; // 0 10 20 30... |
|
| 275 | - |
|
| 276 | - case 'page': |
|
| 277 | - case 'prive': |
|
| 278 | - default: |
|
| 279 | - return $numero_page; // 1 2 3 4 5... |
|
| 280 | - } |
|
| 258 | + if ($numero_page === 'tous') { |
|
| 259 | + return '∞'; |
|
| 260 | + } |
|
| 261 | + if ($numero_page === 'prev') { |
|
| 262 | + return '<'; |
|
| 263 | + } |
|
| 264 | + if ($numero_page === 'next') { |
|
| 265 | + return '>'; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + switch ($type_pagination) { |
|
| 269 | + case 'resultats': |
|
| 270 | + return $rang_item + 1; // 1 11 21 31... |
|
| 271 | + case 'naturel': |
|
| 272 | + return $rang_item ? $rang_item : 1; // 1 10 20 30... |
|
| 273 | + case 'rang': |
|
| 274 | + return $rang_item; // 0 10 20 30... |
|
| 275 | + |
|
| 276 | + case 'page': |
|
| 277 | + case 'prive': |
|
| 278 | + default: |
|
| 279 | + return $numero_page; // 1 2 3 4 5... |
|
| 280 | + } |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -290,15 +290,15 @@ discard block |
||
| 290 | 290 | **/ |
| 291 | 291 | function lister_objets_avec_logos($type) { |
| 292 | 292 | |
| 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)); |
|
| 295 | - if ($ids) { |
|
| 296 | - $ids = array_column($ids, 'id_objet'); |
|
| 297 | - return implode(',', $ids); |
|
| 298 | - } |
|
| 299 | - else { |
|
| 300 | - return '0'; |
|
| 301 | - } |
|
| 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)); |
|
| 295 | + if ($ids) { |
|
| 296 | + $ids = array_column($ids, 'id_objet'); |
|
| 297 | + return implode(',', $ids); |
|
| 298 | + } |
|
| 299 | + else { |
|
| 300 | + return '0'; |
|
| 301 | + } |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | * Code HTML des notes |
| 315 | 315 | **/ |
| 316 | 316 | function calculer_notes() { |
| 317 | - $r = ''; |
|
| 318 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 319 | - $r = $notes([]); |
|
| 320 | - $notes('', 'depiler'); |
|
| 321 | - $notes('', 'empiler'); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - return $r; |
|
| 317 | + $r = ''; |
|
| 318 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 319 | + $r = $notes([]); |
|
| 320 | + $notes('', 'depiler'); |
|
| 321 | + $notes('', 'empiler'); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + return $r; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -338,10 +338,10 @@ discard block |
||
| 338 | 338 | * @return string |
| 339 | 339 | */ |
| 340 | 340 | function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) { |
| 341 | - $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 342 | - $res = array_column($res, 'rang_lien', $objet_source); |
|
| 341 | + $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 342 | + $res = array_column($res, 'rang_lien', $objet_source); |
|
| 343 | 343 | |
| 344 | - return (isset($res[$ids]) ? $res[$ids] : ''); |
|
| 344 | + return (isset($res[$ids]) ? $res[$ids] : ''); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | |
@@ -358,19 +358,19 @@ discard block |
||
| 358 | 358 | * @private |
| 359 | 359 | */ |
| 360 | 360 | function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) { |
| 361 | - static $liens = []; |
|
| 362 | - if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 363 | - include_spip('action/editer_liens'); |
|
| 364 | - // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 365 | - if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 366 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 367 | - } else { |
|
| 368 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 372 | - } |
|
| 373 | - return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 361 | + static $liens = []; |
|
| 362 | + if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 363 | + include_spip('action/editer_liens'); |
|
| 364 | + // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 365 | + if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 366 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 367 | + } else { |
|
| 368 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 372 | + } |
|
| 373 | + return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -384,24 +384,24 @@ discard block |
||
| 384 | 384 | * @return int|string |
| 385 | 385 | */ |
| 386 | 386 | function calculer_rang_smart($titre, $objet_source, $id, $env) { |
| 387 | - // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 388 | - // 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 |
|
| 389 | - if ( |
|
| 390 | - isset($env['form']) and $env['form'] |
|
| 391 | - and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 392 | - and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 393 | - and $r = objet_associable($env['_objet_lien']) |
|
| 394 | - and list($p, $table_lien) = $r |
|
| 395 | - and lien_triables($table_lien) |
|
| 396 | - and isset($env['objet']) and $env['objet'] |
|
| 397 | - and isset($env['id_objet']) and $env['id_objet'] |
|
| 398 | - and $objet_source |
|
| 399 | - and $id = intval($id) |
|
| 400 | - ) { |
|
| 401 | - $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 402 | - return ($rang ? $rang : ''); |
|
| 403 | - } |
|
| 404 | - return recuperer_numero($titre); |
|
| 387 | + // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 388 | + // 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 |
|
| 389 | + if ( |
|
| 390 | + isset($env['form']) and $env['form'] |
|
| 391 | + and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 392 | + and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 393 | + and $r = objet_associable($env['_objet_lien']) |
|
| 394 | + and list($p, $table_lien) = $r |
|
| 395 | + and lien_triables($table_lien) |
|
| 396 | + and isset($env['objet']) and $env['objet'] |
|
| 397 | + and isset($env['id_objet']) and $env['id_objet'] |
|
| 398 | + and $objet_source |
|
| 399 | + and $id = intval($id) |
|
| 400 | + ) { |
|
| 401 | + $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 402 | + return ($rang ? $rang : ''); |
|
| 403 | + } |
|
| 404 | + return recuperer_numero($titre); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | 419 | function tri_protege_champ($t) { |
| 420 | - return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 420 | + return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -430,43 +430,43 @@ discard block |
||
| 430 | 430 | * @return string |
| 431 | 431 | */ |
| 432 | 432 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 433 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 434 | - return 'multi'; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $champ = $t; |
|
| 438 | - |
|
| 439 | - $prefixe = ''; |
|
| 440 | - foreach (['num ', 'sinum '] as $p) { |
|
| 441 | - if (strpos($t, $p) === 0) { |
|
| 442 | - $champ = substr($t, strlen($p)); |
|
| 443 | - $prefixe = $p; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 448 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 449 | - |
|
| 450 | - if (is_array($from)) { |
|
| 451 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 452 | - foreach ($from as $idt => $table_sql) { |
|
| 453 | - if ( |
|
| 454 | - $desc = $trouver_table($table_sql) |
|
| 455 | - and isset($desc['field'][$champ]) |
|
| 456 | - ) { |
|
| 457 | - $champ = "$idt.$champ"; |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - switch ($prefixe) { |
|
| 463 | - case 'num ': |
|
| 464 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 465 | - case 'sinum ': |
|
| 466 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 467 | - default: |
|
| 468 | - return $champ . $senstri; |
|
| 469 | - } |
|
| 433 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 434 | + return 'multi'; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $champ = $t; |
|
| 438 | + |
|
| 439 | + $prefixe = ''; |
|
| 440 | + foreach (['num ', 'sinum '] as $p) { |
|
| 441 | + if (strpos($t, $p) === 0) { |
|
| 442 | + $champ = substr($t, strlen($p)); |
|
| 443 | + $prefixe = $p; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 448 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 449 | + |
|
| 450 | + if (is_array($from)) { |
|
| 451 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 452 | + foreach ($from as $idt => $table_sql) { |
|
| 453 | + if ( |
|
| 454 | + $desc = $trouver_table($table_sql) |
|
| 455 | + and isset($desc['field'][$champ]) |
|
| 456 | + ) { |
|
| 457 | + $champ = "$idt.$champ"; |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + switch ($prefixe) { |
|
| 463 | + case 'num ': |
|
| 464 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 465 | + case 'sinum ': |
|
| 466 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 467 | + default: |
|
| 468 | + return $champ . $senstri; |
|
| 469 | + } |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -480,18 +480,18 @@ discard block |
||
| 480 | 480 | * @return string |
| 481 | 481 | */ |
| 482 | 482 | function tri_champ_select($t) { |
| 483 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 484 | - $t = substr($t, 6); |
|
| 485 | - $t = preg_replace(',\s,', '', $t); |
|
| 486 | - $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 487 | - |
|
| 488 | - return $t; |
|
| 489 | - } |
|
| 490 | - if (trim($t) == 'hasard') { |
|
| 491 | - return 'rand() AS hasard'; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return "''"; |
|
| 483 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 484 | + $t = substr($t, 6); |
|
| 485 | + $t = preg_replace(',\s,', '', $t); |
|
| 486 | + $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 487 | + |
|
| 488 | + return $t; |
|
| 489 | + } |
|
| 490 | + if (trim($t) == 'hasard') { |
|
| 491 | + return 'rand() AS hasard'; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return "''"; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -503,16 +503,16 @@ discard block |
||
| 503 | 503 | * @return string |
| 504 | 504 | */ |
| 505 | 505 | function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') { |
| 506 | - if (!is_array($valeurs)) { |
|
| 507 | - return ''; |
|
| 508 | - } |
|
| 509 | - $f = sql_serveur('quote', $serveur, true); |
|
| 510 | - if (!is_string($f) or !$f) { |
|
| 511 | - return ''; |
|
| 512 | - } |
|
| 513 | - $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 514 | - |
|
| 515 | - return $valeurs; |
|
| 506 | + if (!is_array($valeurs)) { |
|
| 507 | + return ''; |
|
| 508 | + } |
|
| 509 | + $f = sql_serveur('quote', $serveur, true); |
|
| 510 | + if (!is_string($f) or !$f) { |
|
| 511 | + return ''; |
|
| 512 | + } |
|
| 513 | + $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 514 | + |
|
| 515 | + return $valeurs; |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -535,21 +535,21 @@ discard block |
||
| 535 | 535 | * Valeur $defaut sinon. |
| 536 | 536 | **/ |
| 537 | 537 | function appliquer_filtre_sinon($arg, $filtre, $args, $defaut = '') { |
| 538 | - // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 539 | - // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 540 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 541 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 542 | - $args[1] = $args[0]; |
|
| 543 | - $args[0] = $filtre; |
|
| 544 | - return image_graver(image_filtrer($args)); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - $f = chercher_filtre($filtre); |
|
| 548 | - if (!$f) { |
|
| 549 | - return $defaut; |
|
| 550 | - } |
|
| 551 | - array_shift($args); // enlever $arg |
|
| 552 | - array_shift($args); // enlever $filtre |
|
| 553 | - array_unshift($args, $arg); // remettre $arg |
|
| 554 | - return call_user_func_array($f, $args); |
|
| 538 | + // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 539 | + // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 540 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 541 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 542 | + $args[1] = $args[0]; |
|
| 543 | + $args[0] = $filtre; |
|
| 544 | + return image_graver(image_filtrer($args)); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + $f = chercher_filtre($filtre); |
|
| 548 | + if (!$f) { |
|
| 549 | + return $defaut; |
|
| 550 | + } |
|
| 551 | + array_shift($args); // enlever $arg |
|
| 552 | + array_shift($args); // enlever $filtre |
|
| 553 | + array_unshift($args, $arg); // remettre $arg |
|
| 554 | + return call_user_func_array($f, $args); |
|
| 555 | 555 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | $GLOBALS['contexte'] = calculer_contexte(); |
| 39 | 39 | $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
| 40 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 40 | + $page['contexte_implicite']['cache'] = $fond.preg_replace( |
|
| 41 | 41 | ',\.[a-zA-Z0-9]*$,', |
| 42 | 42 | '', |
| 43 | 43 | preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | if ($page === '') { |
| 139 | 139 | $erreur = _T( |
| 140 | 140 | 'info_erreur_squelette2', |
| 141 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 141 | + ['fichier' => spip_htmlspecialchars($fond).'.'._EXTENSION_SQUELETTES] |
|
| 142 | 142 | ); |
| 143 | 143 | erreur_squelette($erreur); |
| 144 | 144 | // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
| 184 | 184 | and !isset($page['entetes']['Last-Modified']) |
| 185 | 185 | ) { |
| 186 | - $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 186 | + $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified).' GMT'; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // fermer la connexion apres les headers si requete HEAD |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | 'spip_version_code' => $GLOBALS['spip_version_code'], |
| 249 | 249 | ]; |
| 250 | 250 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 251 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 251 | + $contexte_implicite['host'] .= '|'.$_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | return $contexte_implicite; |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | if (is_null($id)) { |
| 582 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 582 | + $msg = "modeles/$modele : "._T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 583 | 583 | erreur_squelette($msg); |
| 584 | 584 | // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
| 585 | 585 | $id = 0; |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
| 629 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 629 | + if (!trouve_modele($fond = ($type.'_'.$soustype))) { |
|
| 630 | 630 | $fond = ''; |
| 631 | 631 | $class = $soustype; |
| 632 | 632 | } |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | |
| 642 | 642 | return false; |
| 643 | 643 | } |
| 644 | - $fond = 'modeles/' . $fond; |
|
| 644 | + $fond = 'modeles/'.$fond; |
|
| 645 | 645 | // Creer le contexte |
| 646 | 646 | $contexte = $env; |
| 647 | 647 | $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | // sinon, s'il y a un lien, on l'ajoute classiquement |
| 683 | 683 | if ( |
| 684 | 684 | strstr( |
| 685 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 685 | + ' '.($classes = extraire_attribut($retour, 'class')).' ', |
|
| 686 | 686 | 'spip_lien_ok' |
| 687 | 687 | ) |
| 688 | 688 | ) { |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | ); |
| 694 | 694 | } else { |
| 695 | 695 | if ($lien) { |
| 696 | - $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 696 | + $retour = "<a href='".$lien['href']."' class='".$lien['class']."'>".$retour.'</a>'; |
|
| 697 | 697 | } |
| 698 | 698 | } |
| 699 | 699 | |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | return $page; |
| 718 | 718 | } |
| 719 | 719 | // eval $page et affecte $res |
| 720 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 720 | + include _ROOT_RESTREINT.'public/evaluer_page.php'; |
|
| 721 | 721 | |
| 722 | 722 | // Lever un drapeau (global) si le fond utilise #SESSION |
| 723 | 723 | // a destination de public/parametrer |
@@ -785,16 +785,16 @@ discard block |
||
| 785 | 785 | if (($pos = strpos($head, '<head>')) !== false) { |
| 786 | 786 | $head = substr_replace($head, $base, $pos + 6, 0); |
| 787 | 787 | } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
| 788 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 788 | + $head = str_replace($r[0], $r[0].$base, $head); |
|
| 789 | 789 | } |
| 790 | - $texte = $head . substr($texte, $poshead); |
|
| 790 | + $texte = $head.substr($texte, $poshead); |
|
| 791 | 791 | } |
| 792 | 792 | if ($href_base) { |
| 793 | 793 | // gerer les ancres |
| 794 | 794 | $base = $_SERVER['REQUEST_URI']; |
| 795 | 795 | // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
| 796 | 796 | if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
| 797 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 797 | + $base = str_replace(["'", '"', '<'], ['%27', '%22', '%3C'], $base); |
|
| 798 | 798 | } |
| 799 | 799 | if (strpos($texte, "href='#") !== false) { |
| 800 | 800 | $texte = str_replace("href='#", "href='$base#", $texte); |
@@ -20,178 +20,178 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // En cas de modification, il faut aussi actualiser la regexp de nettoyer_uri_var() dans inc/utils.php |
| 27 | 27 | if (!defined('_CONTEXTE_IGNORE_VARIABLES')) { |
| 28 | - define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 28 | + define('_CONTEXTE_IGNORE_VARIABLES', '/(^var_|^PHPSESSID$|^fbclid$|^utm_)/'); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // https://code.spip.net/@assembler |
| 32 | 32 | function assembler($fond, $connect = '') { |
| 33 | 33 | |
| 34 | - // flag_preserver est modifie ici, et utilise en globale |
|
| 35 | - // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 36 | - // contexte est utilise en globale dans le formulaire d'admin |
|
| 37 | - |
|
| 38 | - $GLOBALS['contexte'] = calculer_contexte(); |
|
| 39 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 40 | - $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 41 | - ',\.[a-zA-Z0-9]*$,', |
|
| 42 | - '', |
|
| 43 | - preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 44 | - ); |
|
| 45 | - // Cette fonction est utilisee deux fois |
|
| 46 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 47 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 48 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 49 | - if ($cacher) { |
|
| 50 | - $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 51 | - } else { |
|
| 52 | - $GLOBALS['use_cache'] = -1; |
|
| 53 | - } |
|
| 54 | - // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 55 | - if ($res) { |
|
| 56 | - return ['texte' => $res]; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if (!$chemin_cache || !$lastmodified) { |
|
| 60 | - $lastmodified = time(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 64 | - $calculer_page = true; |
|
| 65 | - |
|
| 66 | - // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 67 | - // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 68 | - // pages sont dynamiques) |
|
| 69 | - if ( |
|
| 70 | - isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 71 | - and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 72 | - and $chemin_cache |
|
| 73 | - and isset($page['entetes']) |
|
| 74 | - and isset($page['entetes']['Cache-Control']) |
|
| 75 | - and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 76 | - and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 77 | - ) { |
|
| 78 | - $since = preg_replace( |
|
| 79 | - '/;.*/', |
|
| 80 | - '', |
|
| 81 | - $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 82 | - ); |
|
| 83 | - $since = str_replace('GMT', '', $since); |
|
| 84 | - if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 85 | - $page['status'] = 304; |
|
| 86 | - $headers_only = true; |
|
| 87 | - $calculer_page = false; |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 92 | - // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 93 | - if (!$calculer_page) { |
|
| 94 | - $page['texte'] = ''; |
|
| 95 | - } else { |
|
| 96 | - // si la page est prise dans le cache |
|
| 97 | - if (!$GLOBALS['use_cache']) { |
|
| 98 | - // Informer les boutons d'admin du contexte |
|
| 99 | - // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 100 | - $GLOBALS['contexte'] = $page['contexte']; |
|
| 101 | - |
|
| 102 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 103 | - // d'inversion url => objet |
|
| 104 | - // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 105 | - #unset($_SERVER['REDIRECT_url_propre']); |
|
| 106 | - #unset($_ENV['url_propre']); |
|
| 107 | - } else { |
|
| 108 | - // Compat ascendante : |
|
| 109 | - // 1. $contexte est global |
|
| 110 | - // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 111 | - // et calculer la page |
|
| 112 | - if (!test_espace_prive()) { |
|
| 113 | - include_spip('inc/urls'); |
|
| 114 | - list($fond, $GLOBALS['contexte'], $url_redirect) = urls_decoder_url( |
|
| 115 | - nettoyer_uri(), |
|
| 116 | - $fond, |
|
| 117 | - $GLOBALS['contexte'], |
|
| 118 | - true |
|
| 119 | - ); |
|
| 120 | - } |
|
| 121 | - // squelette par defaut |
|
| 122 | - if (!strlen($fond)) { |
|
| 123 | - $fond = 'sommaire'; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // produire la page : peut mettre a jour $lastmodified |
|
| 127 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 128 | - $page = $produire_page( |
|
| 129 | - $fond, |
|
| 130 | - $GLOBALS['contexte'], |
|
| 131 | - $GLOBALS['use_cache'], |
|
| 132 | - $chemin_cache, |
|
| 133 | - null, |
|
| 134 | - $page, |
|
| 135 | - $lastmodified, |
|
| 136 | - $connect |
|
| 137 | - ); |
|
| 138 | - if ($page === '') { |
|
| 139 | - $erreur = _T( |
|
| 140 | - 'info_erreur_squelette2', |
|
| 141 | - ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 142 | - ); |
|
| 143 | - erreur_squelette($erreur); |
|
| 144 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 145 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - if ($page and $chemin_cache) { |
|
| 150 | - $page['cache'] = $chemin_cache; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - auto_content_type($page); |
|
| 154 | - |
|
| 155 | - $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 156 | - |
|
| 157 | - // Definir les entetes si ce n'est fait |
|
| 158 | - if (!$GLOBALS['flag_preserver']) { |
|
| 159 | - if ($GLOBALS['flag_ob']) { |
|
| 160 | - // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 161 | - if ( |
|
| 162 | - trim($page['texte']) === '' |
|
| 163 | - and _VAR_MODE != 'debug' |
|
| 164 | - and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 165 | - ) { |
|
| 166 | - $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 167 | - $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 168 | - } |
|
| 169 | - // pas de cache client en mode 'observation' |
|
| 170 | - if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 171 | - $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 172 | - $page['entetes']['Pragma'] = 'no-cache'; |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Entete Last-Modified: |
|
| 179 | - // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 180 | - // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 181 | - if ( |
|
| 182 | - $lastmodified |
|
| 183 | - and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 184 | - and !isset($page['entetes']['Last-Modified']) |
|
| 185 | - ) { |
|
| 186 | - $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // fermer la connexion apres les headers si requete HEAD |
|
| 190 | - if ($headers_only) { |
|
| 191 | - $page['entetes']['Connection'] = 'close'; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $page; |
|
| 34 | + // flag_preserver est modifie ici, et utilise en globale |
|
| 35 | + // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 36 | + // contexte est utilise en globale dans le formulaire d'admin |
|
| 37 | + |
|
| 38 | + $GLOBALS['contexte'] = calculer_contexte(); |
|
| 39 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 40 | + $page['contexte_implicite']['cache'] = $fond . preg_replace( |
|
| 41 | + ',\.[a-zA-Z0-9]*$,', |
|
| 42 | + '', |
|
| 43 | + preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI']) |
|
| 44 | + ); |
|
| 45 | + // Cette fonction est utilisee deux fois |
|
| 46 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 47 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 48 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 49 | + if ($cacher) { |
|
| 50 | + $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 51 | + } else { |
|
| 52 | + $GLOBALS['use_cache'] = -1; |
|
| 53 | + } |
|
| 54 | + // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 55 | + if ($res) { |
|
| 56 | + return ['texte' => $res]; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if (!$chemin_cache || !$lastmodified) { |
|
| 60 | + $lastmodified = time(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 64 | + $calculer_page = true; |
|
| 65 | + |
|
| 66 | + // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 67 | + // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 68 | + // pages sont dynamiques) |
|
| 69 | + if ( |
|
| 70 | + isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 71 | + and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 72 | + and $chemin_cache |
|
| 73 | + and isset($page['entetes']) |
|
| 74 | + and isset($page['entetes']['Cache-Control']) |
|
| 75 | + and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 76 | + and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 77 | + ) { |
|
| 78 | + $since = preg_replace( |
|
| 79 | + '/;.*/', |
|
| 80 | + '', |
|
| 81 | + $_SERVER['HTTP_IF_MODIFIED_SINCE'] |
|
| 82 | + ); |
|
| 83 | + $since = str_replace('GMT', '', $since); |
|
| 84 | + if (trim($since) == gmdate('D, d M Y H:i:s', $lastmodified)) { |
|
| 85 | + $page['status'] = 304; |
|
| 86 | + $headers_only = true; |
|
| 87 | + $calculer_page = false; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 92 | + // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 93 | + if (!$calculer_page) { |
|
| 94 | + $page['texte'] = ''; |
|
| 95 | + } else { |
|
| 96 | + // si la page est prise dans le cache |
|
| 97 | + if (!$GLOBALS['use_cache']) { |
|
| 98 | + // Informer les boutons d'admin du contexte |
|
| 99 | + // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 100 | + $GLOBALS['contexte'] = $page['contexte']; |
|
| 101 | + |
|
| 102 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 103 | + // d'inversion url => objet |
|
| 104 | + // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 105 | + #unset($_SERVER['REDIRECT_url_propre']); |
|
| 106 | + #unset($_ENV['url_propre']); |
|
| 107 | + } else { |
|
| 108 | + // Compat ascendante : |
|
| 109 | + // 1. $contexte est global |
|
| 110 | + // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 111 | + // et calculer la page |
|
| 112 | + if (!test_espace_prive()) { |
|
| 113 | + include_spip('inc/urls'); |
|
| 114 | + list($fond, $GLOBALS['contexte'], $url_redirect) = urls_decoder_url( |
|
| 115 | + nettoyer_uri(), |
|
| 116 | + $fond, |
|
| 117 | + $GLOBALS['contexte'], |
|
| 118 | + true |
|
| 119 | + ); |
|
| 120 | + } |
|
| 121 | + // squelette par defaut |
|
| 122 | + if (!strlen($fond)) { |
|
| 123 | + $fond = 'sommaire'; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // produire la page : peut mettre a jour $lastmodified |
|
| 127 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 128 | + $page = $produire_page( |
|
| 129 | + $fond, |
|
| 130 | + $GLOBALS['contexte'], |
|
| 131 | + $GLOBALS['use_cache'], |
|
| 132 | + $chemin_cache, |
|
| 133 | + null, |
|
| 134 | + $page, |
|
| 135 | + $lastmodified, |
|
| 136 | + $connect |
|
| 137 | + ); |
|
| 138 | + if ($page === '') { |
|
| 139 | + $erreur = _T( |
|
| 140 | + 'info_erreur_squelette2', |
|
| 141 | + ['fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES] |
|
| 142 | + ); |
|
| 143 | + erreur_squelette($erreur); |
|
| 144 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 145 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + if ($page and $chemin_cache) { |
|
| 150 | + $page['cache'] = $chemin_cache; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + auto_content_type($page); |
|
| 154 | + |
|
| 155 | + $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 156 | + |
|
| 157 | + // Definir les entetes si ce n'est fait |
|
| 158 | + if (!$GLOBALS['flag_preserver']) { |
|
| 159 | + if ($GLOBALS['flag_ob']) { |
|
| 160 | + // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 161 | + if ( |
|
| 162 | + trim($page['texte']) === '' |
|
| 163 | + and _VAR_MODE != 'debug' |
|
| 164 | + and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 165 | + ) { |
|
| 166 | + $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 167 | + $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 168 | + } |
|
| 169 | + // pas de cache client en mode 'observation' |
|
| 170 | + if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 171 | + $page['entetes']['Cache-Control'] = 'no-cache,must-revalidate'; |
|
| 172 | + $page['entetes']['Pragma'] = 'no-cache'; |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Entete Last-Modified: |
|
| 179 | + // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 180 | + // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 181 | + if ( |
|
| 182 | + $lastmodified |
|
| 183 | + and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 184 | + and !isset($page['entetes']['Last-Modified']) |
|
| 185 | + ) { |
|
| 186 | + $page['entetes']['Last-Modified'] = gmdate('D, d M Y H:i:s', $lastmodified) . ' GMT'; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // fermer la connexion apres les headers si requete HEAD |
|
| 190 | + if ($headers_only) { |
|
| 191 | + $page['entetes']['Connection'] = 'close'; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $page; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -210,19 +210,19 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | function calculer_contexte() { |
| 212 | 212 | |
| 213 | - $contexte = []; |
|
| 214 | - foreach ($_GET as $var => $val) { |
|
| 215 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 216 | - $contexte[$var] = $val; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - foreach ($_POST as $var => $val) { |
|
| 220 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 221 | - $contexte[$var] = $val; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - return $contexte; |
|
| 213 | + $contexte = []; |
|
| 214 | + foreach ($_GET as $var => $val) { |
|
| 215 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 216 | + $contexte[$var] = $val; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + foreach ($_POST as $var => $val) { |
|
| 220 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 221 | + $contexte[$var] = $val; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + return $contexte; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -233,25 +233,25 @@ discard block |
||
| 233 | 233 | * @return array |
| 234 | 234 | */ |
| 235 | 235 | function calculer_contexte_implicite() { |
| 236 | - static $notes = null; |
|
| 237 | - if (is_null($notes)) { |
|
| 238 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 239 | - } |
|
| 240 | - $contexte_implicite = [ |
|
| 241 | - 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 242 | - 'host' => (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null), |
|
| 243 | - 'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''), |
|
| 244 | - 'espace' => test_espace_prive(), |
|
| 245 | - 'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''), |
|
| 246 | - 'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''), |
|
| 247 | - 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 248 | - 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 249 | - ]; |
|
| 250 | - if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 251 | - $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return $contexte_implicite; |
|
| 236 | + static $notes = null; |
|
| 237 | + if (is_null($notes)) { |
|
| 238 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 239 | + } |
|
| 240 | + $contexte_implicite = [ |
|
| 241 | + 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 242 | + 'host' => (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null), |
|
| 243 | + 'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''), |
|
| 244 | + 'espace' => test_espace_prive(), |
|
| 245 | + 'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''), |
|
| 246 | + 'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''), |
|
| 247 | + 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 248 | + 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 249 | + ]; |
|
| 250 | + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 251 | + $contexte_implicite['host'] .= '|' . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return $contexte_implicite; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // |
@@ -261,52 +261,52 @@ discard block |
||
| 261 | 261 | // https://code.spip.net/@auto_content_type |
| 262 | 262 | function auto_content_type($page) { |
| 263 | 263 | |
| 264 | - if (!isset($GLOBALS['flag_preserver'])) { |
|
| 265 | - $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 266 | - '/header\s*\(\s*.content\-type:/isx', |
|
| 267 | - $page['texte'] |
|
| 268 | - ) || (isset($page['entetes']['Content-Type']))); |
|
| 269 | - } |
|
| 264 | + if (!isset($GLOBALS['flag_preserver'])) { |
|
| 265 | + $GLOBALS['flag_preserver'] = ($page && preg_match( |
|
| 266 | + '/header\s*\(\s*.content\-type:/isx', |
|
| 267 | + $page['texte'] |
|
| 268 | + ) || (isset($page['entetes']['Content-Type']))); |
|
| 269 | + } |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | // https://code.spip.net/@inclure_page |
| 273 | 273 | function inclure_page($fond, $contexte, $connect = '') { |
| 274 | - static $cacher, $produire_page; |
|
| 275 | - |
|
| 276 | - // enlever le fond de contexte inclus car sinon il prend la main |
|
| 277 | - // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 278 | - // (cette precaution n'est probablement plus utile) |
|
| 279 | - unset($contexte['fond']); |
|
| 280 | - $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 281 | - $page['contexte_implicite']['cache'] = $fond; |
|
| 282 | - if (is_null($cacher)) { |
|
| 283 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 284 | - } |
|
| 285 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 286 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 287 | - if ($cacher) { |
|
| 288 | - $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 289 | - } else { |
|
| 290 | - $use_cache = -1; |
|
| 291 | - } |
|
| 292 | - // $res = message d'erreur : on sort de la |
|
| 293 | - if ($res) { |
|
| 294 | - return ['texte' => $res]; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 298 | - // produire la page : peut mettre a jour $lastinclude |
|
| 299 | - // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 300 | - if ($use_cache) { |
|
| 301 | - if (is_null($produire_page)) { |
|
| 302 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 303 | - } |
|
| 304 | - $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 305 | - } |
|
| 306 | - // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 307 | - $GLOBALS['lastmodified'] = max((isset($GLOBALS['lastmodified']) ? $GLOBALS['lastmodified'] : 0), $lastinclude); |
|
| 308 | - |
|
| 309 | - return $page; |
|
| 274 | + static $cacher, $produire_page; |
|
| 275 | + |
|
| 276 | + // enlever le fond de contexte inclus car sinon il prend la main |
|
| 277 | + // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 278 | + // (cette precaution n'est probablement plus utile) |
|
| 279 | + unset($contexte['fond']); |
|
| 280 | + $page = ['contexte_implicite' => calculer_contexte_implicite()]; |
|
| 281 | + $page['contexte_implicite']['cache'] = $fond; |
|
| 282 | + if (is_null($cacher)) { |
|
| 283 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 284 | + } |
|
| 285 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 286 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 287 | + if ($cacher) { |
|
| 288 | + $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 289 | + } else { |
|
| 290 | + $use_cache = -1; |
|
| 291 | + } |
|
| 292 | + // $res = message d'erreur : on sort de la |
|
| 293 | + if ($res) { |
|
| 294 | + return ['texte' => $res]; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 298 | + // produire la page : peut mettre a jour $lastinclude |
|
| 299 | + // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 300 | + if ($use_cache) { |
|
| 301 | + if (is_null($produire_page)) { |
|
| 302 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 303 | + } |
|
| 304 | + $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 305 | + } |
|
| 306 | + // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 307 | + $GLOBALS['lastmodified'] = max((isset($GLOBALS['lastmodified']) ? $GLOBALS['lastmodified'] : 0), $lastinclude); |
|
| 308 | + |
|
| 309 | + return $page; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -324,41 +324,41 @@ discard block |
||
| 324 | 324 | * @return array |
| 325 | 325 | */ |
| 326 | 326 | function public_produire_page_dist( |
| 327 | - $fond, |
|
| 328 | - $contexte, |
|
| 329 | - $use_cache, |
|
| 330 | - $chemin_cache, |
|
| 331 | - $contexte_cache, |
|
| 332 | - &$page, |
|
| 333 | - &$lastinclude, |
|
| 334 | - $connect = '' |
|
| 327 | + $fond, |
|
| 328 | + $contexte, |
|
| 329 | + $use_cache, |
|
| 330 | + $chemin_cache, |
|
| 331 | + $contexte_cache, |
|
| 332 | + &$page, |
|
| 333 | + &$lastinclude, |
|
| 334 | + $connect = '' |
|
| 335 | 335 | ) { |
| 336 | - static $parametrer, $cacher; |
|
| 337 | - if (!$parametrer) { |
|
| 338 | - $parametrer = charger_fonction('parametrer', 'public'); |
|
| 339 | - } |
|
| 340 | - $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 341 | - // et on l'enregistre sur le disque |
|
| 342 | - if ( |
|
| 343 | - $chemin_cache |
|
| 344 | - and $use_cache > -1 |
|
| 345 | - and is_array($page) |
|
| 346 | - and count($page) |
|
| 347 | - and isset($page['entetes']['X-Spip-Cache']) |
|
| 348 | - and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 349 | - ) { |
|
| 350 | - if (is_null($cacher)) { |
|
| 351 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 352 | - } |
|
| 353 | - $lastinclude = time(); |
|
| 354 | - if ($cacher) { |
|
| 355 | - $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 356 | - } else { |
|
| 357 | - $use_cache = -1; |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return $page; |
|
| 336 | + static $parametrer, $cacher; |
|
| 337 | + if (!$parametrer) { |
|
| 338 | + $parametrer = charger_fonction('parametrer', 'public'); |
|
| 339 | + } |
|
| 340 | + $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 341 | + // et on l'enregistre sur le disque |
|
| 342 | + if ( |
|
| 343 | + $chemin_cache |
|
| 344 | + and $use_cache > -1 |
|
| 345 | + and is_array($page) |
|
| 346 | + and count($page) |
|
| 347 | + and isset($page['entetes']['X-Spip-Cache']) |
|
| 348 | + and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 349 | + ) { |
|
| 350 | + if (is_null($cacher)) { |
|
| 351 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 352 | + } |
|
| 353 | + $lastinclude = time(); |
|
| 354 | + if ($cacher) { |
|
| 355 | + $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 356 | + } else { |
|
| 357 | + $use_cache = -1; |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return $page; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Fonction inseree par le compilateur dans le code compile. |
@@ -372,14 +372,14 @@ discard block |
||
| 372 | 372 | // 4: langue |
| 373 | 373 | |
| 374 | 374 | function inserer_balise_dynamique($contexte_exec, $contexte_compil) { |
| 375 | - arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 376 | - |
|
| 377 | - if (!is_array($contexte_exec)) { |
|
| 378 | - echo $contexte_exec; |
|
| 379 | - } // message d'erreur etc |
|
| 380 | - else { |
|
| 381 | - inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 382 | - } |
|
| 375 | + arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 376 | + |
|
| 377 | + if (!is_array($contexte_exec)) { |
|
| 378 | + echo $contexte_exec; |
|
| 379 | + } // message d'erreur etc |
|
| 380 | + else { |
|
| 381 | + inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 382 | + } |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -394,100 +394,100 @@ discard block |
||
| 394 | 394 | * @return string |
| 395 | 395 | */ |
| 396 | 396 | function inclure_balise_dynamique($texte, $echo = true, $contexte_compil = []) { |
| 397 | - if (is_array($texte)) { |
|
| 398 | - list($fond, $delainc, $contexte_inclus) = $texte; |
|
| 399 | - |
|
| 400 | - // delais a l'ancienne, c'est pratiquement mort |
|
| 401 | - $d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : null; |
|
| 402 | - $GLOBALS['delais'] = $delainc; |
|
| 403 | - |
|
| 404 | - $page = recuperer_fond( |
|
| 405 | - $fond, |
|
| 406 | - $contexte_inclus, |
|
| 407 | - ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 408 | - ); |
|
| 409 | - |
|
| 410 | - $texte = $page['texte']; |
|
| 411 | - |
|
| 412 | - $GLOBALS['delais'] = $d; |
|
| 413 | - // Faire remonter les entetes |
|
| 414 | - if (is_array($page['entetes'])) { |
|
| 415 | - // mais pas toutes |
|
| 416 | - unset($page['entetes']['X-Spip-Cache']); |
|
| 417 | - unset($page['entetes']['Content-Type']); |
|
| 418 | - if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 419 | - if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 420 | - $GLOBALS['page']['entetes'] = []; |
|
| 421 | - } |
|
| 422 | - $GLOBALS['page']['entetes'] = |
|
| 423 | - array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 427 | - if ( |
|
| 428 | - isset($page['contexte']['_pipelines']) |
|
| 429 | - and is_array($page['contexte']['_pipelines']) |
|
| 430 | - and count($page['contexte']['_pipelines']) |
|
| 431 | - ) { |
|
| 432 | - foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 433 | - $args['contexte'] = $page['contexte']; |
|
| 434 | - unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 435 | - $texte = pipeline( |
|
| 436 | - $pipe, |
|
| 437 | - [ |
|
| 438 | - 'data' => $texte, |
|
| 439 | - 'args' => $args |
|
| 440 | - ], |
|
| 441 | - false |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 448 | - // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 449 | - $ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil); |
|
| 450 | - $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 451 | - } |
|
| 452 | - if ($echo) { |
|
| 453 | - echo $texte; |
|
| 454 | - } else { |
|
| 455 | - return $texte; |
|
| 456 | - } |
|
| 397 | + if (is_array($texte)) { |
|
| 398 | + list($fond, $delainc, $contexte_inclus) = $texte; |
|
| 399 | + |
|
| 400 | + // delais a l'ancienne, c'est pratiquement mort |
|
| 401 | + $d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : null; |
|
| 402 | + $GLOBALS['delais'] = $delainc; |
|
| 403 | + |
|
| 404 | + $page = recuperer_fond( |
|
| 405 | + $fond, |
|
| 406 | + $contexte_inclus, |
|
| 407 | + ['trim' => false, 'raw' => true, 'compil' => $contexte_compil] |
|
| 408 | + ); |
|
| 409 | + |
|
| 410 | + $texte = $page['texte']; |
|
| 411 | + |
|
| 412 | + $GLOBALS['delais'] = $d; |
|
| 413 | + // Faire remonter les entetes |
|
| 414 | + if (is_array($page['entetes'])) { |
|
| 415 | + // mais pas toutes |
|
| 416 | + unset($page['entetes']['X-Spip-Cache']); |
|
| 417 | + unset($page['entetes']['Content-Type']); |
|
| 418 | + if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 419 | + if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 420 | + $GLOBALS['page']['entetes'] = []; |
|
| 421 | + } |
|
| 422 | + $GLOBALS['page']['entetes'] = |
|
| 423 | + array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 427 | + if ( |
|
| 428 | + isset($page['contexte']['_pipelines']) |
|
| 429 | + and is_array($page['contexte']['_pipelines']) |
|
| 430 | + and count($page['contexte']['_pipelines']) |
|
| 431 | + ) { |
|
| 432 | + foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 433 | + $args['contexte'] = $page['contexte']; |
|
| 434 | + unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 435 | + $texte = pipeline( |
|
| 436 | + $pipe, |
|
| 437 | + [ |
|
| 438 | + 'data' => $texte, |
|
| 439 | + 'args' => $args |
|
| 440 | + ], |
|
| 441 | + false |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 448 | + // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 449 | + $ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil); |
|
| 450 | + $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 451 | + } |
|
| 452 | + if ($echo) { |
|
| 453 | + echo $texte; |
|
| 454 | + } else { |
|
| 455 | + return $texte; |
|
| 456 | + } |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | // https://code.spip.net/@message_page_indisponible |
| 460 | 460 | function message_page_indisponible($page, $contexte) { |
| 461 | - static $deja = false; |
|
| 462 | - if ($deja) { |
|
| 463 | - return 'erreur'; |
|
| 464 | - } |
|
| 465 | - $codes = [ |
|
| 466 | - '404' => '404 Not Found', |
|
| 467 | - '503' => '503 Service Unavailable', |
|
| 468 | - ]; |
|
| 469 | - |
|
| 470 | - $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 471 | - $contexte['code'] = $codes[$contexte['status']]; |
|
| 472 | - $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 473 | - if (!isset($contexte['lang'])) { |
|
| 474 | - include_spip('inc/lang'); |
|
| 475 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - $deja = true; |
|
| 479 | - // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 480 | - // ex restriction d'acces => 401 |
|
| 481 | - $contexte = pipeline('page_indisponible', $contexte); |
|
| 482 | - |
|
| 483 | - // produire la page d'erreur |
|
| 484 | - $page = inclure_page($contexte['fond'], $contexte); |
|
| 485 | - if (!$page) { |
|
| 486 | - $page = inclure_page('404', $contexte); |
|
| 487 | - } |
|
| 488 | - $page['status'] = $contexte['status']; |
|
| 489 | - |
|
| 490 | - return $page; |
|
| 461 | + static $deja = false; |
|
| 462 | + if ($deja) { |
|
| 463 | + return 'erreur'; |
|
| 464 | + } |
|
| 465 | + $codes = [ |
|
| 466 | + '404' => '404 Not Found', |
|
| 467 | + '503' => '503 Service Unavailable', |
|
| 468 | + ]; |
|
| 469 | + |
|
| 470 | + $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 471 | + $contexte['code'] = $codes[$contexte['status']]; |
|
| 472 | + $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 473 | + if (!isset($contexte['lang'])) { |
|
| 474 | + include_spip('inc/lang'); |
|
| 475 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + $deja = true; |
|
| 479 | + // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 480 | + // ex restriction d'acces => 401 |
|
| 481 | + $contexte = pipeline('page_indisponible', $contexte); |
|
| 482 | + |
|
| 483 | + // produire la page d'erreur |
|
| 484 | + $page = inclure_page($contexte['fond'], $contexte); |
|
| 485 | + if (!$page) { |
|
| 486 | + $page = inclure_page('404', $contexte); |
|
| 487 | + } |
|
| 488 | + $page['status'] = $contexte['status']; |
|
| 489 | + |
|
| 490 | + return $page; |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | /** |
@@ -499,45 +499,45 @@ discard block |
||
| 499 | 499 | * @return mixed |
| 500 | 500 | */ |
| 501 | 501 | function arguments_balise_dyn_depuis_modele($arg, $operation = 'set') { |
| 502 | - static $balise_dyn_appellee_par_modele = null; |
|
| 503 | - switch ($operation) { |
|
| 504 | - case 'read': |
|
| 505 | - return $balise_dyn_appellee_par_modele; |
|
| 506 | - case 'reset': |
|
| 507 | - $balise_dyn_appellee_par_modele = null; |
|
| 508 | - return null; |
|
| 509 | - case 'set': |
|
| 510 | - default: |
|
| 511 | - $balise_dyn_appellee_par_modele = $arg; |
|
| 512 | - return $arg; |
|
| 513 | - } |
|
| 502 | + static $balise_dyn_appellee_par_modele = null; |
|
| 503 | + switch ($operation) { |
|
| 504 | + case 'read': |
|
| 505 | + return $balise_dyn_appellee_par_modele; |
|
| 506 | + case 'reset': |
|
| 507 | + $balise_dyn_appellee_par_modele = null; |
|
| 508 | + return null; |
|
| 509 | + case 'set': |
|
| 510 | + default: |
|
| 511 | + $balise_dyn_appellee_par_modele = $arg; |
|
| 512 | + return $arg; |
|
| 513 | + } |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | // temporairement ici : a mettre dans le futur inc/modeles |
| 517 | 517 | // creer_contexte_de_modele('left', 'autostart=true', ...) renvoie un array() |
| 518 | 518 | // https://code.spip.net/@creer_contexte_de_modele |
| 519 | 519 | function creer_contexte_de_modele($args) { |
| 520 | - $contexte = []; |
|
| 521 | - foreach ($args as $var => $val) { |
|
| 522 | - if (is_int($var)) { // argument pas formate |
|
| 523 | - if (in_array($val, ['left', 'right', 'center'])) { |
|
| 524 | - $var = 'align'; |
|
| 525 | - $contexte[$var] = $val; |
|
| 526 | - } else { |
|
| 527 | - $args = explode('=', $val); |
|
| 528 | - if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 529 | - $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 530 | - } else // notation abregee |
|
| 531 | - { |
|
| 532 | - $contexte[trim($val)] = trim($val); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } else { |
|
| 536 | - $contexte[$var] = $val; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - return $contexte; |
|
| 520 | + $contexte = []; |
|
| 521 | + foreach ($args as $var => $val) { |
|
| 522 | + if (is_int($var)) { // argument pas formate |
|
| 523 | + if (in_array($val, ['left', 'right', 'center'])) { |
|
| 524 | + $var = 'align'; |
|
| 525 | + $contexte[$var] = $val; |
|
| 526 | + } else { |
|
| 527 | + $args = explode('=', $val); |
|
| 528 | + if (count($args) >= 2) { // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 529 | + $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 530 | + } else // notation abregee |
|
| 531 | + { |
|
| 532 | + $contexte[trim($val)] = trim($val); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } else { |
|
| 536 | + $contexte[$var] = $val; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + return $contexte; |
|
| 541 | 541 | } |
| 542 | 542 | |
| 543 | 543 | /** |
@@ -552,43 +552,43 @@ discard block |
||
| 552 | 552 | * @return string |
| 553 | 553 | */ |
| 554 | 554 | function styliser_modele($modele, $id, $contexte = null) { |
| 555 | - static $styliseurs = null; |
|
| 556 | - if (is_null($styliseurs)) { |
|
| 557 | - $tables_objet = lister_tables_objets_sql(); |
|
| 558 | - foreach ($tables_objet as $table => $desc) { |
|
| 559 | - if ( |
|
| 560 | - isset($desc['modeles']) and $desc['modeles'] |
|
| 561 | - and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 562 | - and function_exists($desc['modeles_styliser']) |
|
| 563 | - ) { |
|
| 564 | - $primary = id_table_objet($table); |
|
| 565 | - foreach ($desc['modeles'] as $m) { |
|
| 566 | - $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - if (isset($styliseurs[$modele])) { |
|
| 573 | - $styliseur = $styliseurs[$modele]['callback']; |
|
| 574 | - $primary = $styliseurs[$modele]['primary']; |
|
| 575 | - if (is_null($id) and $contexte) { |
|
| 576 | - if (isset($contexte['id'])) { |
|
| 577 | - $id = $contexte['id']; |
|
| 578 | - } elseif (isset($contexte[$primary])) { |
|
| 579 | - $id = $contexte[$primary]; |
|
| 580 | - } |
|
| 581 | - } |
|
| 582 | - if (is_null($id)) { |
|
| 583 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 584 | - erreur_squelette($msg); |
|
| 585 | - // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 586 | - $id = 0; |
|
| 587 | - } |
|
| 588 | - $modele = $styliseur($modele, $id); |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - return $modele; |
|
| 555 | + static $styliseurs = null; |
|
| 556 | + if (is_null($styliseurs)) { |
|
| 557 | + $tables_objet = lister_tables_objets_sql(); |
|
| 558 | + foreach ($tables_objet as $table => $desc) { |
|
| 559 | + if ( |
|
| 560 | + isset($desc['modeles']) and $desc['modeles'] |
|
| 561 | + and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 562 | + and function_exists($desc['modeles_styliser']) |
|
| 563 | + ) { |
|
| 564 | + $primary = id_table_objet($table); |
|
| 565 | + foreach ($desc['modeles'] as $m) { |
|
| 566 | + $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + if (isset($styliseurs[$modele])) { |
|
| 573 | + $styliseur = $styliseurs[$modele]['callback']; |
|
| 574 | + $primary = $styliseurs[$modele]['primary']; |
|
| 575 | + if (is_null($id) and $contexte) { |
|
| 576 | + if (isset($contexte['id'])) { |
|
| 577 | + $id = $contexte['id']; |
|
| 578 | + } elseif (isset($contexte[$primary])) { |
|
| 579 | + $id = $contexte[$primary]; |
|
| 580 | + } |
|
| 581 | + } |
|
| 582 | + if (is_null($id)) { |
|
| 583 | + $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', ['param' => "id/$primary"]); |
|
| 584 | + erreur_squelette($msg); |
|
| 585 | + // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 586 | + $id = 0; |
|
| 587 | + } |
|
| 588 | + $modele = $styliseur($modele, $id); |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + return $modele; |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | /** |
@@ -607,102 +607,102 @@ discard block |
||
| 607 | 607 | */ |
| 608 | 608 | function inclure_modele($type, $id, $params, $lien, $connect = '', $env = []) { |
| 609 | 609 | |
| 610 | - static $compteur; |
|
| 611 | - if (++$compteur > 10) { |
|
| 612 | - return ''; |
|
| 613 | - } # ne pas boucler indefiniment |
|
| 614 | - |
|
| 615 | - $type = strtolower($type); |
|
| 616 | - $type = styliser_modele($type, $id); |
|
| 617 | - |
|
| 618 | - $fond = $class = ''; |
|
| 619 | - |
|
| 620 | - $params = array_filter(explode('|', $params)); |
|
| 621 | - if ($params) { |
|
| 622 | - $soustype = current($params); |
|
| 623 | - $soustype = strtolower(trim($soustype)); |
|
| 624 | - if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 625 | - $soustype = next($params); |
|
| 626 | - $soustype = strtolower($soustype); |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 630 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 631 | - $fond = ''; |
|
| 632 | - $class = $soustype; |
|
| 633 | - } |
|
| 634 | - // enlever le sous type des params |
|
| 635 | - $params = array_diff($params, [$soustype]); |
|
| 636 | - } |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 640 | - if (!$fond and !trouve_modele($fond = $type)) { |
|
| 641 | - spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 642 | - |
|
| 643 | - return false; |
|
| 644 | - } |
|
| 645 | - $fond = 'modeles/' . $fond; |
|
| 646 | - // Creer le contexte |
|
| 647 | - $contexte = $env; |
|
| 648 | - $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 649 | - |
|
| 650 | - // Le numero du modele est mis dans l'environnement |
|
| 651 | - // d'une part sous l'identifiant "id" |
|
| 652 | - // et d'autre part sous l'identifiant de la cle primaire |
|
| 653 | - // par la fonction id_table_objet, |
|
| 654 | - // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 655 | - $_id = id_table_objet($type); |
|
| 656 | - $contexte['id'] = $contexte[$_id] = $id; |
|
| 657 | - |
|
| 658 | - if (isset($class)) { |
|
| 659 | - $contexte['class'] = $class; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 663 | - if ($lien) { |
|
| 664 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 665 | - $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 666 | - $contexte['lien_class'] = $lien['class']; |
|
| 667 | - $contexte['lien_mime'] = $lien['mime']; |
|
| 668 | - $contexte['lien_title'] = $lien['title']; |
|
| 669 | - $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 670 | - } |
|
| 671 | - |
|
| 672 | - // Traiter les parametres |
|
| 673 | - // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 674 | - $arg_list = creer_contexte_de_modele($params); |
|
| 675 | - $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 676 | - $contexte = array_merge($contexte, $arg_list); |
|
| 677 | - |
|
| 678 | - // Appliquer le modele avec le contexte |
|
| 679 | - $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 680 | - |
|
| 681 | - // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 682 | - // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 683 | - // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 684 | - if ( |
|
| 685 | - strstr( |
|
| 686 | - ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 687 | - 'spip_lien_ok' |
|
| 688 | - ) |
|
| 689 | - ) { |
|
| 690 | - $retour = inserer_attribut( |
|
| 691 | - $retour, |
|
| 692 | - 'class', |
|
| 693 | - trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 694 | - ); |
|
| 695 | - } else { |
|
| 696 | - if ($lien) { |
|
| 697 | - $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - $compteur--; |
|
| 702 | - |
|
| 703 | - return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 704 | - ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 705 | - : $retour; |
|
| 610 | + static $compteur; |
|
| 611 | + if (++$compteur > 10) { |
|
| 612 | + return ''; |
|
| 613 | + } # ne pas boucler indefiniment |
|
| 614 | + |
|
| 615 | + $type = strtolower($type); |
|
| 616 | + $type = styliser_modele($type, $id); |
|
| 617 | + |
|
| 618 | + $fond = $class = ''; |
|
| 619 | + |
|
| 620 | + $params = array_filter(explode('|', $params)); |
|
| 621 | + if ($params) { |
|
| 622 | + $soustype = current($params); |
|
| 623 | + $soustype = strtolower(trim($soustype)); |
|
| 624 | + if (in_array($soustype, ['left', 'right', 'center', 'ajax'])) { |
|
| 625 | + $soustype = next($params); |
|
| 626 | + $soustype = strtolower($soustype); |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 630 | + if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 631 | + $fond = ''; |
|
| 632 | + $class = $soustype; |
|
| 633 | + } |
|
| 634 | + // enlever le sous type des params |
|
| 635 | + $params = array_diff($params, [$soustype]); |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 640 | + if (!$fond and !trouve_modele($fond = $type)) { |
|
| 641 | + spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 642 | + |
|
| 643 | + return false; |
|
| 644 | + } |
|
| 645 | + $fond = 'modeles/' . $fond; |
|
| 646 | + // Creer le contexte |
|
| 647 | + $contexte = $env; |
|
| 648 | + $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 649 | + |
|
| 650 | + // Le numero du modele est mis dans l'environnement |
|
| 651 | + // d'une part sous l'identifiant "id" |
|
| 652 | + // et d'autre part sous l'identifiant de la cle primaire |
|
| 653 | + // par la fonction id_table_objet, |
|
| 654 | + // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 655 | + $_id = id_table_objet($type); |
|
| 656 | + $contexte['id'] = $contexte[$_id] = $id; |
|
| 657 | + |
|
| 658 | + if (isset($class)) { |
|
| 659 | + $contexte['class'] = $class; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 663 | + if ($lien) { |
|
| 664 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 665 | + $contexte['lien'] = str_replace('"', '"', $lien['href']); |
|
| 666 | + $contexte['lien_class'] = $lien['class']; |
|
| 667 | + $contexte['lien_mime'] = $lien['mime']; |
|
| 668 | + $contexte['lien_title'] = $lien['title']; |
|
| 669 | + $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 670 | + } |
|
| 671 | + |
|
| 672 | + // Traiter les parametres |
|
| 673 | + // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 674 | + $arg_list = creer_contexte_de_modele($params); |
|
| 675 | + $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 676 | + $contexte = array_merge($contexte, $arg_list); |
|
| 677 | + |
|
| 678 | + // Appliquer le modele avec le contexte |
|
| 679 | + $retour = recuperer_fond($fond, $contexte, [], $connect); |
|
| 680 | + |
|
| 681 | + // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 682 | + // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 683 | + // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 684 | + if ( |
|
| 685 | + strstr( |
|
| 686 | + ' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 687 | + 'spip_lien_ok' |
|
| 688 | + ) |
|
| 689 | + ) { |
|
| 690 | + $retour = inserer_attribut( |
|
| 691 | + $retour, |
|
| 692 | + 'class', |
|
| 693 | + trim(str_replace(' spip_lien_ok ', ' ', " $classes ")) |
|
| 694 | + ); |
|
| 695 | + } else { |
|
| 696 | + if ($lien) { |
|
| 697 | + $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . '</a>'; |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + $compteur--; |
|
| 702 | + |
|
| 703 | + return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 704 | + ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 705 | + : $retour; |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | // Un inclure_page qui marche aussi pour l'espace prive |
@@ -712,99 +712,99 @@ discard block |
||
| 712 | 712 | // https://code.spip.net/@evaluer_fond |
| 713 | 713 | function evaluer_fond($fond, $contexte = [], $connect = null) { |
| 714 | 714 | |
| 715 | - $page = inclure_page($fond, $contexte, $connect); |
|
| 716 | - |
|
| 717 | - if (!$page) { |
|
| 718 | - return $page; |
|
| 719 | - } |
|
| 720 | - // eval $page et affecte $res |
|
| 721 | - include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 722 | - |
|
| 723 | - // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 724 | - // a destination de public/parametrer |
|
| 725 | - // pour remonter vers les inclusions appelantes |
|
| 726 | - // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 727 | - // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 728 | - if ( |
|
| 729 | - isset($page['invalideurs']) |
|
| 730 | - and isset($page['invalideurs']['session']) |
|
| 731 | - ) { |
|
| 732 | - $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - return $page; |
|
| 715 | + $page = inclure_page($fond, $contexte, $connect); |
|
| 716 | + |
|
| 717 | + if (!$page) { |
|
| 718 | + return $page; |
|
| 719 | + } |
|
| 720 | + // eval $page et affecte $res |
|
| 721 | + include _ROOT_RESTREINT . 'public/evaluer_page.php'; |
|
| 722 | + |
|
| 723 | + // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 724 | + // a destination de public/parametrer |
|
| 725 | + // pour remonter vers les inclusions appelantes |
|
| 726 | + // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 727 | + // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 728 | + if ( |
|
| 729 | + isset($page['invalideurs']) |
|
| 730 | + and isset($page['invalideurs']['session']) |
|
| 731 | + ) { |
|
| 732 | + $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + return $page; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
| 739 | 739 | // https://code.spip.net/@page_base_href |
| 740 | 740 | function page_base_href(&$texte) { |
| 741 | - static $set_html_base = null; |
|
| 742 | - if (is_null($set_html_base)) { |
|
| 743 | - if (!defined('_SET_HTML_BASE')) { |
|
| 744 | - // si la profondeur est superieure a 1 |
|
| 745 | - // est que ce n'est pas une url page ni une url action |
|
| 746 | - // activer par defaut |
|
| 747 | - $set_html_base = (( |
|
| 748 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 749 | - and _request(_SPIP_PAGE) !== 'login' |
|
| 750 | - and !_request('action')) ? true : false); |
|
| 751 | - } else { |
|
| 752 | - $set_html_base = _SET_HTML_BASE; |
|
| 753 | - } |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if ( |
|
| 757 | - $set_html_base |
|
| 758 | - and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 759 | - and $GLOBALS['profondeur_url'] > 0 |
|
| 760 | - and ($poshead = strpos($texte, '</head>')) !== false |
|
| 761 | - ) { |
|
| 762 | - $head = substr($texte, 0, $poshead); |
|
| 763 | - $insert = false; |
|
| 764 | - $href_base = false; |
|
| 765 | - if (strpos($head, '<base') === false) { |
|
| 766 | - $insert = true; |
|
| 767 | - } else { |
|
| 768 | - // si aucun <base ...> n'a de href il faut en inserer un |
|
| 769 | - // sinon juste re-ecrire les ancres si besoin |
|
| 770 | - $insert = true; |
|
| 771 | - include_spip('inc/filtres'); |
|
| 772 | - $bases = extraire_balises($head, 'base'); |
|
| 773 | - foreach ($bases as $base) { |
|
| 774 | - if ($href_base = extraire_attribut($base, 'href')) { |
|
| 775 | - $insert = false; |
|
| 776 | - break; |
|
| 777 | - } |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - if ($insert) { |
|
| 782 | - include_spip('inc/filtres_mini'); |
|
| 783 | - // ajouter un base qui reglera tous les liens relatifs |
|
| 784 | - $href_base = url_absolue('./'); |
|
| 785 | - $base = "\n<base href=\"$href_base\" />"; |
|
| 786 | - if (($pos = strpos($head, '<head>')) !== false) { |
|
| 787 | - $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 788 | - } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 789 | - $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 790 | - } |
|
| 791 | - $texte = $head . substr($texte, $poshead); |
|
| 792 | - } |
|
| 793 | - if ($href_base) { |
|
| 794 | - // gerer les ancres |
|
| 795 | - $base = $_SERVER['REQUEST_URI']; |
|
| 796 | - // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 797 | - if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 798 | - $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 799 | - } |
|
| 800 | - if (strpos($texte, "href='#") !== false) { |
|
| 801 | - $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 802 | - } |
|
| 803 | - if (strpos($texte, 'href="#') !== false) { |
|
| 804 | - $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 805 | - } |
|
| 806 | - } |
|
| 807 | - } |
|
| 741 | + static $set_html_base = null; |
|
| 742 | + if (is_null($set_html_base)) { |
|
| 743 | + if (!defined('_SET_HTML_BASE')) { |
|
| 744 | + // si la profondeur est superieure a 1 |
|
| 745 | + // est que ce n'est pas une url page ni une url action |
|
| 746 | + // activer par defaut |
|
| 747 | + $set_html_base = (( |
|
| 748 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 749 | + and _request(_SPIP_PAGE) !== 'login' |
|
| 750 | + and !_request('action')) ? true : false); |
|
| 751 | + } else { |
|
| 752 | + $set_html_base = _SET_HTML_BASE; |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if ( |
|
| 757 | + $set_html_base |
|
| 758 | + and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 759 | + and $GLOBALS['profondeur_url'] > 0 |
|
| 760 | + and ($poshead = strpos($texte, '</head>')) !== false |
|
| 761 | + ) { |
|
| 762 | + $head = substr($texte, 0, $poshead); |
|
| 763 | + $insert = false; |
|
| 764 | + $href_base = false; |
|
| 765 | + if (strpos($head, '<base') === false) { |
|
| 766 | + $insert = true; |
|
| 767 | + } else { |
|
| 768 | + // si aucun <base ...> n'a de href il faut en inserer un |
|
| 769 | + // sinon juste re-ecrire les ancres si besoin |
|
| 770 | + $insert = true; |
|
| 771 | + include_spip('inc/filtres'); |
|
| 772 | + $bases = extraire_balises($head, 'base'); |
|
| 773 | + foreach ($bases as $base) { |
|
| 774 | + if ($href_base = extraire_attribut($base, 'href')) { |
|
| 775 | + $insert = false; |
|
| 776 | + break; |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + if ($insert) { |
|
| 782 | + include_spip('inc/filtres_mini'); |
|
| 783 | + // ajouter un base qui reglera tous les liens relatifs |
|
| 784 | + $href_base = url_absolue('./'); |
|
| 785 | + $base = "\n<base href=\"$href_base\" />"; |
|
| 786 | + if (($pos = strpos($head, '<head>')) !== false) { |
|
| 787 | + $head = substr_replace($head, $base, $pos + 6, 0); |
|
| 788 | + } elseif (preg_match(',<head[^>]*>,i', $head, $r)) { |
|
| 789 | + $head = str_replace($r[0], $r[0] . $base, $head); |
|
| 790 | + } |
|
| 791 | + $texte = $head . substr($texte, $poshead); |
|
| 792 | + } |
|
| 793 | + if ($href_base) { |
|
| 794 | + // gerer les ancres |
|
| 795 | + $base = $_SERVER['REQUEST_URI']; |
|
| 796 | + // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 797 | + if (strpos($base, "'") or strpos($base, '"') or strpos($base, '<')) { |
|
| 798 | + $base = str_replace(["'",'"','<'], ['%27','%22','%3C'], $base); |
|
| 799 | + } |
|
| 800 | + if (strpos($texte, "href='#") !== false) { |
|
| 801 | + $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 802 | + } |
|
| 803 | + if (strpos($texte, 'href="#') !== false) { |
|
| 804 | + $texte = str_replace('href="#', "href=\"$base#", $texte); |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | // et demarrent par X-Spip-... |
| 813 | 813 | // https://code.spip.net/@envoyer_entetes |
| 814 | 814 | function envoyer_entetes($entetes) { |
| 815 | - foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 816 | - @header(strlen($v) ? "$k: $v" : $k); |
|
| 817 | - } |
|
| 815 | + foreach ($entetes as $k => $v) { # if (strncmp($k, 'X-Spip-', 7)) |
|
| 816 | + @header(strlen($v) ? "$k: $v" : $k); |
|
| 817 | + } |
|
| 818 | 818 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte'); |
@@ -43,233 +43,233 @@ discard block |
||
| 43 | 43 | // https://code.spip.net/@public_composer_dist |
| 44 | 44 | function public_composer_dist($squelette, $mime_type, $gram, $source, $connect = '') { |
| 45 | 45 | |
| 46 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | - |
|
| 48 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | - if (function_exists($nom)) { |
|
| 50 | - return $nom; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | - |
|
| 59 | - // si squelette est deja compile et perenne, le charger |
|
| 60 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | - include_once $phpfile; |
|
| 62 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | - ## eval('?'.'>'.$skel_code); |
|
| 66 | - # spip_log($skel_code, 'comp') |
|
| 67 | - #} |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | - include_once $lib; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | - |
|
| 76 | - if (function_exists($nom)) { |
|
| 77 | - return $nom; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // charger le source, si possible, et compiler |
|
| 81 | - $skel_code = ''; |
|
| 82 | - if (lire_fichier($source, $skel)) { |
|
| 83 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | - if (!$skel_code) { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - foreach ($skel_code as $id => $boucle) { |
|
| 93 | - $f = $boucle->return; |
|
| 94 | - try { |
|
| 95 | - eval("return true; $f ;"); |
|
| 96 | - } catch (\ParseError $e) { |
|
| 97 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 98 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | - erreur_squelette($msg, $boucle); |
|
| 100 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 101 | - // mais prevenir que c'est mort |
|
| 102 | - $nom = ''; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Contexte de compil inutile a present |
|
| 106 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 107 | - $skel_code[$id] = $f; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $code = ''; |
|
| 111 | - if ($nom) { |
|
| 112 | - // Si le code est bon, concatener et mettre en cache |
|
| 113 | - if (function_exists($nom)) { |
|
| 114 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 115 | - } else { |
|
| 116 | - // code semantiquement faux: bug du compilateur |
|
| 117 | - // $boucle est en fait ici la fct principale du squelette |
|
| 118 | - $msg = _T('zbug_erreur_compilation'); |
|
| 119 | - erreur_squelette($msg, $boucle); |
|
| 120 | - $nom = ''; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 125 | - // Tracer ce qui vient d'etre compile |
|
| 126 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | - |
|
| 128 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 129 | - if ( |
|
| 130 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 131 | - and (_request('var_mode_objet') == $nom) |
|
| 132 | - and (_request('var_mode_affiche') == 'code') |
|
| 133 | - ) { |
|
| 134 | - erreur_squelette(); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $nom ? $nom : false; |
|
| 46 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | + |
|
| 48 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | + if (function_exists($nom)) { |
|
| 50 | + return $nom; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | + |
|
| 59 | + // si squelette est deja compile et perenne, le charger |
|
| 60 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | + include_once $phpfile; |
|
| 62 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | + ## eval('?'.'>'.$skel_code); |
|
| 66 | + # spip_log($skel_code, 'comp') |
|
| 67 | + #} |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | + include_once $lib; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | + |
|
| 76 | + if (function_exists($nom)) { |
|
| 77 | + return $nom; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // charger le source, si possible, et compiler |
|
| 81 | + $skel_code = ''; |
|
| 82 | + if (lire_fichier($source, $skel)) { |
|
| 83 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | + if (!$skel_code) { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + foreach ($skel_code as $id => $boucle) { |
|
| 93 | + $f = $boucle->return; |
|
| 94 | + try { |
|
| 95 | + eval("return true; $f ;"); |
|
| 96 | + } catch (\ParseError $e) { |
|
| 97 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 98 | + $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | + erreur_squelette($msg, $boucle); |
|
| 100 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 101 | + // mais prevenir que c'est mort |
|
| 102 | + $nom = ''; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Contexte de compil inutile a present |
|
| 106 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 107 | + $skel_code[$id] = $f; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $code = ''; |
|
| 111 | + if ($nom) { |
|
| 112 | + // Si le code est bon, concatener et mettre en cache |
|
| 113 | + if (function_exists($nom)) { |
|
| 114 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 115 | + } else { |
|
| 116 | + // code semantiquement faux: bug du compilateur |
|
| 117 | + // $boucle est en fait ici la fct principale du squelette |
|
| 118 | + $msg = _T('zbug_erreur_compilation'); |
|
| 119 | + erreur_squelette($msg, $boucle); |
|
| 120 | + $nom = ''; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 125 | + // Tracer ce qui vient d'etre compile |
|
| 126 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | + |
|
| 128 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 129 | + if ( |
|
| 130 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 131 | + and (_request('var_mode_objet') == $nom) |
|
| 132 | + and (_request('var_mode_affiche') == 'code') |
|
| 133 | + ) { |
|
| 134 | + erreur_squelette(); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $nom ? $nom : false; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 142 | 142 | |
| 143 | - // Le dernier index est '' (fonction principale) |
|
| 144 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 145 | - if (CODE_COMMENTE) { |
|
| 146 | - $code = " |
|
| 143 | + // Le dernier index est '' (fonction principale) |
|
| 144 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 145 | + if (CODE_COMMENTE) { |
|
| 146 | + $code = " |
|
| 147 | 147 | /* |
| 148 | 148 | * Squelette : $sourcefile |
| 149 | 149 | * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
| 150 | 150 | * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
| 151 | 151 | * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
| 152 | 152 | */ '; |
| 153 | - } |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 156 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 157 | - ecrire_fichier($phpfile, $code); |
|
| 158 | - } |
|
| 155 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 156 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 157 | + ecrire_fichier($phpfile, $code); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - return $code; |
|
| 160 | + return $code; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Le squelette compile est-il trop vieux ? |
| 164 | 164 | // https://code.spip.net/@squelette_obsolete |
| 165 | 165 | function squelette_obsolete($skel, $squelette) { |
| 166 | - static $date_change = null; |
|
| 167 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 168 | - // par hit |
|
| 169 | - if (is_null($date_change)) { |
|
| 170 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 171 | - $date_change = @filemtime($fonc); |
|
| 172 | - } # compatibilite |
|
| 173 | - if (defined('_FILE_OPTIONS')) { |
|
| 174 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return ( |
|
| 179 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 180 | - or !@file_exists($skel) |
|
| 181 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 182 | - > ($date = @filemtime($skel))) |
|
| 183 | - or ($date_change > $date) |
|
| 184 | - ); |
|
| 166 | + static $date_change = null; |
|
| 167 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 168 | + // par hit |
|
| 169 | + if (is_null($date_change)) { |
|
| 170 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 171 | + $date_change = @filemtime($fonc); |
|
| 172 | + } # compatibilite |
|
| 173 | + if (defined('_FILE_OPTIONS')) { |
|
| 174 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return ( |
|
| 179 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 180 | + or !@file_exists($skel) |
|
| 181 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 182 | + > ($date = @filemtime($skel))) |
|
| 183 | + or ($date_change > $date) |
|
| 184 | + ); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Activer l'invalideur de session |
| 188 | 188 | // https://code.spip.net/@invalideur_session |
| 189 | 189 | function invalideur_session(&$Cache, $code = null) { |
| 190 | - $Cache['session'] = spip_session(); |
|
| 190 | + $Cache['session'] = spip_session(); |
|
| 191 | 191 | |
| 192 | - return $code; |
|
| 192 | + return $code; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
| 196 | 196 | // https://code.spip.net/@analyse_resultat_skel |
| 197 | 197 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 198 | - static $filtres = []; |
|
| 199 | - $headers = []; |
|
| 200 | - |
|
| 201 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 202 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 203 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 204 | - if ( |
|
| 205 | - stripos($corps, 'header') !== false |
|
| 206 | - and preg_match_all( |
|
| 207 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 208 | - $corps, |
|
| 209 | - $regs, |
|
| 210 | - PREG_SET_ORDER |
|
| 211 | - ) |
|
| 212 | - ) { |
|
| 213 | - foreach ($regs as $r) { |
|
| 214 | - $corps = str_replace($r[0], '', $corps); |
|
| 215 | - # $j = Content-Type, et pas content-TYPE. |
|
| 216 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 217 | - |
|
| 218 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 219 | - $headers[$j] .= '|' . $r[3]; |
|
| 220 | - } else { |
|
| 221 | - $headers[$j] = $r[3]; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 226 | - $process_ins = ( |
|
| 227 | - strpos($corps, '<' . '?') === false |
|
| 228 | - or |
|
| 229 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 231 | - ) |
|
| 232 | - ? 'html' |
|
| 233 | - : 'php'; |
|
| 234 | - |
|
| 235 | - $skel = [ |
|
| 236 | - 'squelette' => $nom, |
|
| 237 | - 'source' => $source, |
|
| 238 | - 'process_ins' => $process_ins, |
|
| 239 | - 'invalideurs' => $cache, |
|
| 240 | - 'entetes' => $headers, |
|
| 241 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 242 | - ]; |
|
| 243 | - |
|
| 244 | - // traiter #FILTRE{} et filtres |
|
| 245 | - if (!isset($filtres[$nom])) { |
|
| 246 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 247 | - } |
|
| 248 | - $filtres_headers = []; |
|
| 249 | - if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 250 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 251 | - unset($headers['X-Spip-Filtre']); |
|
| 252 | - } |
|
| 253 | - if (count($filtres[$nom]) or count($filtres_headers)) { |
|
| 254 | - include_spip('public/sandbox'); |
|
| 255 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 256 | - |
|
| 257 | - if ($process_ins == 'html') { |
|
| 258 | - $skel['process_ins'] = ( |
|
| 259 | - strpos($corps, '<' . '?') === false |
|
| 260 | - or |
|
| 261 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 263 | - ) |
|
| 264 | - ? 'html' |
|
| 265 | - : 'php'; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $skel['entetes'] = $headers; |
|
| 270 | - $skel['texte'] = $corps; |
|
| 271 | - |
|
| 272 | - return $skel; |
|
| 198 | + static $filtres = []; |
|
| 199 | + $headers = []; |
|
| 200 | + |
|
| 201 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 202 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 203 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 204 | + if ( |
|
| 205 | + stripos($corps, 'header') !== false |
|
| 206 | + and preg_match_all( |
|
| 207 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 208 | + $corps, |
|
| 209 | + $regs, |
|
| 210 | + PREG_SET_ORDER |
|
| 211 | + ) |
|
| 212 | + ) { |
|
| 213 | + foreach ($regs as $r) { |
|
| 214 | + $corps = str_replace($r[0], '', $corps); |
|
| 215 | + # $j = Content-Type, et pas content-TYPE. |
|
| 216 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 217 | + |
|
| 218 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 219 | + $headers[$j] .= '|' . $r[3]; |
|
| 220 | + } else { |
|
| 221 | + $headers[$j] = $r[3]; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 226 | + $process_ins = ( |
|
| 227 | + strpos($corps, '<' . '?') === false |
|
| 228 | + or |
|
| 229 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 231 | + ) |
|
| 232 | + ? 'html' |
|
| 233 | + : 'php'; |
|
| 234 | + |
|
| 235 | + $skel = [ |
|
| 236 | + 'squelette' => $nom, |
|
| 237 | + 'source' => $source, |
|
| 238 | + 'process_ins' => $process_ins, |
|
| 239 | + 'invalideurs' => $cache, |
|
| 240 | + 'entetes' => $headers, |
|
| 241 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 242 | + ]; |
|
| 243 | + |
|
| 244 | + // traiter #FILTRE{} et filtres |
|
| 245 | + if (!isset($filtres[$nom])) { |
|
| 246 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 247 | + } |
|
| 248 | + $filtres_headers = []; |
|
| 249 | + if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 250 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 251 | + unset($headers['X-Spip-Filtre']); |
|
| 252 | + } |
|
| 253 | + if (count($filtres[$nom]) or count($filtres_headers)) { |
|
| 254 | + include_spip('public/sandbox'); |
|
| 255 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 256 | + |
|
| 257 | + if ($process_ins == 'html') { |
|
| 258 | + $skel['process_ins'] = ( |
|
| 259 | + strpos($corps, '<' . '?') === false |
|
| 260 | + or |
|
| 261 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 263 | + ) |
|
| 264 | + ? 'html' |
|
| 265 | + : 'php'; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $skel['entetes'] = $headers; |
|
| 270 | + $skel['texte'] = $corps; |
|
| 271 | + |
|
| 272 | + return $skel; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 284 | 284 | if ($lang_select) lang_select(); |
| 285 | 285 | ?' |
| 286 | - . '>'); |
|
| 286 | + . '>'); |
|
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -303,35 +303,35 @@ discard block |
||
| 303 | 303 | * Code PHP pour inclure le squelette de la balise dynamique |
| 304 | 304 | **/ |
| 305 | 305 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 306 | - if ( |
|
| 307 | - strncmp($file, '/', 1) !== 0 |
|
| 308 | - // pas de lien symbolique sous Windows |
|
| 309 | - and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
|
| 310 | - ) { |
|
| 311 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $lang = $context_compil[4]; |
|
| 315 | - if (preg_match(',\W,', $lang)) { |
|
| 316 | - $lang = ''; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $args = array_map('argumenter_squelette', $args); |
|
| 320 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 321 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 322 | - } |
|
| 323 | - $args = join(', ', $args); |
|
| 324 | - |
|
| 325 | - $r = sprintf( |
|
| 326 | - CODE_INCLURE_BALISE, |
|
| 327 | - $file, |
|
| 328 | - $lang, |
|
| 329 | - $nom, |
|
| 330 | - $args, |
|
| 331 | - join(', ', array_map('_q', $context_compil)) |
|
| 332 | - ); |
|
| 333 | - |
|
| 334 | - return $r; |
|
| 306 | + if ( |
|
| 307 | + strncmp($file, '/', 1) !== 0 |
|
| 308 | + // pas de lien symbolique sous Windows |
|
| 309 | + and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
|
| 310 | + ) { |
|
| 311 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $lang = $context_compil[4]; |
|
| 315 | + if (preg_match(',\W,', $lang)) { |
|
| 316 | + $lang = ''; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $args = array_map('argumenter_squelette', $args); |
|
| 320 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 321 | + $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 322 | + } |
|
| 323 | + $args = join(', ', $args); |
|
| 324 | + |
|
| 325 | + $r = sprintf( |
|
| 326 | + CODE_INCLURE_BALISE, |
|
| 327 | + $file, |
|
| 328 | + $lang, |
|
| 329 | + $nom, |
|
| 330 | + $args, |
|
| 331 | + join(', ', array_map('_q', $context_compil)) |
|
| 332 | + ); |
|
| 333 | + |
|
| 334 | + return $r; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -349,18 +349,18 @@ discard block |
||
| 349 | 349 | **/ |
| 350 | 350 | function argumenter_squelette($v) { |
| 351 | 351 | |
| 352 | - if (is_object($v)) { |
|
| 353 | - return var_export($v, true); |
|
| 354 | - } elseif (!is_array($v)) { |
|
| 355 | - return "'" . texte_script($v) . "'"; |
|
| 356 | - } else { |
|
| 357 | - $out = []; |
|
| 358 | - foreach ($v as $k => $val) { |
|
| 359 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return 'array(' . join(', ', $out) . ')'; |
|
| 363 | - } |
|
| 352 | + if (is_object($v)) { |
|
| 353 | + return var_export($v, true); |
|
| 354 | + } elseif (!is_array($v)) { |
|
| 355 | + return "'" . texte_script($v) . "'"; |
|
| 356 | + } else { |
|
| 357 | + $out = []; |
|
| 358 | + foreach ($v as $k => $val) { |
|
| 359 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return 'array(' . join(', ', $out) . ')'; |
|
| 363 | + } |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
@@ -391,87 +391,87 @@ discard block |
||
| 391 | 391 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 392 | 392 | **/ |
| 393 | 393 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 394 | - /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 395 | - $nom_balise = $nom; |
|
| 396 | - /** @var string Nom de la balise générique (si utilisée) */ |
|
| 397 | - $nom_balise_generique = ''; |
|
| 398 | - |
|
| 399 | - $appel_php_depuis_modele = false; |
|
| 400 | - if ( |
|
| 401 | - is_array($context_compil) |
|
| 402 | - and !is_numeric($context_compil[3]) |
|
| 403 | - and empty($context_compil[0]) |
|
| 404 | - and empty($context_compil[1]) |
|
| 405 | - and empty($context_compil[2]) |
|
| 406 | - and empty($context_compil[3]) |
|
| 407 | - ) { |
|
| 408 | - $appel_php_depuis_modele = true; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 412 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 413 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 414 | - // injecter en premier arg le nom de la balise |
|
| 415 | - array_unshift($args, $nom); |
|
| 416 | - $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 417 | - $fonction_balise = $balise_generique['fonction_generique']; |
|
| 418 | - $nom_balise = $nom_balise_generique; |
|
| 419 | - } |
|
| 420 | - unset($balise_generique); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if (!$fonction_balise) { |
|
| 424 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 425 | - erreur_squelette($msg, $context_compil); |
|
| 426 | - |
|
| 427 | - return ''; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - // retrouver le fichier qui a déclaré la fonction |
|
| 431 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 432 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 433 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 434 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 435 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 436 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 440 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 441 | - |
|
| 442 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 443 | - |
|
| 444 | - if (!is_array($r)) { |
|
| 445 | - return $r; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - // verifier que la fonction dyn est la, |
|
| 449 | - // sinon se replier sur la generique si elle existe |
|
| 450 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 451 | - if ( |
|
| 452 | - $balise_generique = chercher_balise_generique($nom) |
|
| 453 | - and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 454 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 455 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 456 | - ) { |
|
| 457 | - // et lui injecter en premier arg le nom de la balise |
|
| 458 | - array_unshift($r, $nom); |
|
| 459 | - $nom_balise = $nom_balise_generique; |
|
| 460 | - if (!_DIR_RESTREINT) { |
|
| 461 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 462 | - } |
|
| 463 | - } else { |
|
| 464 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 465 | - erreur_squelette($msg, $context_compil); |
|
| 466 | - |
|
| 467 | - return ''; |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - if ($appel_php_depuis_modele) { |
|
| 472 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 473 | - } |
|
| 474 | - return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 394 | + /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 395 | + $nom_balise = $nom; |
|
| 396 | + /** @var string Nom de la balise générique (si utilisée) */ |
|
| 397 | + $nom_balise_generique = ''; |
|
| 398 | + |
|
| 399 | + $appel_php_depuis_modele = false; |
|
| 400 | + if ( |
|
| 401 | + is_array($context_compil) |
|
| 402 | + and !is_numeric($context_compil[3]) |
|
| 403 | + and empty($context_compil[0]) |
|
| 404 | + and empty($context_compil[1]) |
|
| 405 | + and empty($context_compil[2]) |
|
| 406 | + and empty($context_compil[3]) |
|
| 407 | + ) { |
|
| 408 | + $appel_php_depuis_modele = true; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 412 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 413 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 414 | + // injecter en premier arg le nom de la balise |
|
| 415 | + array_unshift($args, $nom); |
|
| 416 | + $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 417 | + $fonction_balise = $balise_generique['fonction_generique']; |
|
| 418 | + $nom_balise = $nom_balise_generique; |
|
| 419 | + } |
|
| 420 | + unset($balise_generique); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if (!$fonction_balise) { |
|
| 424 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 425 | + erreur_squelette($msg, $context_compil); |
|
| 426 | + |
|
| 427 | + return ''; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + // retrouver le fichier qui a déclaré la fonction |
|
| 431 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 432 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 433 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 434 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 435 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 436 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 440 | + $f = 'balise_' . $nom_balise . '_stat'; |
|
| 441 | + |
|
| 442 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 443 | + |
|
| 444 | + if (!is_array($r)) { |
|
| 445 | + return $r; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + // verifier que la fonction dyn est la, |
|
| 449 | + // sinon se replier sur la generique si elle existe |
|
| 450 | + if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 451 | + if ( |
|
| 452 | + $balise_generique = chercher_balise_generique($nom) |
|
| 453 | + and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 454 | + and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 455 | + and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 456 | + ) { |
|
| 457 | + // et lui injecter en premier arg le nom de la balise |
|
| 458 | + array_unshift($r, $nom); |
|
| 459 | + $nom_balise = $nom_balise_generique; |
|
| 460 | + if (!_DIR_RESTREINT) { |
|
| 461 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 462 | + } |
|
| 463 | + } else { |
|
| 464 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 465 | + erreur_squelette($msg, $context_compil); |
|
| 466 | + |
|
| 467 | + return ''; |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + if ($appel_php_depuis_modele) { |
|
| 472 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 473 | + } |
|
| 474 | + return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
@@ -486,23 +486,23 @@ discard block |
||
| 486 | 486 | * @return array|null |
| 487 | 487 | */ |
| 488 | 488 | function chercher_balise_generique($nom) { |
| 489 | - if (false === strpos($nom, '_')) { |
|
| 490 | - return null; |
|
| 491 | - } |
|
| 492 | - $nom_generique = $nom; |
|
| 493 | - while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 494 | - $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 495 | - $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 496 | - if ($fonction_generique) { |
|
| 497 | - return [ |
|
| 498 | - 'nom' => $nom, |
|
| 499 | - 'nom_generique' => $nom_generique, |
|
| 500 | - 'fonction_generique' => $fonction_generique, |
|
| 501 | - ]; |
|
| 502 | - } |
|
| 503 | - $nom_generique = substr($nom_generique, 0, -1); |
|
| 504 | - } |
|
| 505 | - return null; |
|
| 489 | + if (false === strpos($nom, '_')) { |
|
| 490 | + return null; |
|
| 491 | + } |
|
| 492 | + $nom_generique = $nom; |
|
| 493 | + while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 494 | + $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 495 | + $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 496 | + if ($fonction_generique) { |
|
| 497 | + return [ |
|
| 498 | + 'nom' => $nom, |
|
| 499 | + 'nom_generique' => $nom_generique, |
|
| 500 | + 'fonction_generique' => $fonction_generique, |
|
| 501 | + ]; |
|
| 502 | + } |
|
| 503 | + $nom_generique = substr($nom_generique, 0, -1); |
|
| 504 | + } |
|
| 505 | + return null; |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | |
@@ -526,29 +526,29 @@ discard block |
||
| 526 | 526 | * @return null; |
| 527 | 527 | **/ |
| 528 | 528 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 529 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 530 | - if ( |
|
| 531 | - isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 532 | - and $lang_select !== 'oui' |
|
| 533 | - ) { |
|
| 534 | - $lang = $GLOBALS['spip_lang']; |
|
| 535 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 536 | - elseif (!strlen($lang)) { |
|
| 537 | - $lang = $GLOBALS['spip_lang']; |
|
| 538 | - } // Cas 3. l'objet est multilingue ! |
|
| 539 | - elseif ( |
|
| 540 | - $lang_select !== 'oui' |
|
| 541 | - and strlen($titre) > 10 |
|
| 542 | - and strpos($titre, '<multi>') !== false |
|
| 543 | - and strpos(echappe_html($titre), '<multi>') !== false |
|
| 544 | - ) { |
|
| 545 | - $lang = $GLOBALS['spip_lang']; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 549 | - lang_select($lang); |
|
| 550 | - |
|
| 551 | - return; |
|
| 529 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 530 | + if ( |
|
| 531 | + isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 532 | + and $lang_select !== 'oui' |
|
| 533 | + ) { |
|
| 534 | + $lang = $GLOBALS['spip_lang']; |
|
| 535 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 536 | + elseif (!strlen($lang)) { |
|
| 537 | + $lang = $GLOBALS['spip_lang']; |
|
| 538 | + } // Cas 3. l'objet est multilingue ! |
|
| 539 | + elseif ( |
|
| 540 | + $lang_select !== 'oui' |
|
| 541 | + and strlen($titre) > 10 |
|
| 542 | + and strpos($titre, '<multi>') !== false |
|
| 543 | + and strpos(echappe_html($titre), '<multi>') !== false |
|
| 544 | + ) { |
|
| 545 | + $lang = $GLOBALS['spip_lang']; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 549 | + lang_select($lang); |
|
| 550 | + |
|
| 551 | + return; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -556,21 +556,21 @@ discard block |
||
| 556 | 556 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 557 | 557 | // https://code.spip.net/@nettoyer_env_doublons |
| 558 | 558 | function nettoyer_env_doublons($envd) { |
| 559 | - foreach ($envd as $table => $liste) { |
|
| 560 | - $n = ''; |
|
| 561 | - foreach (explode(',', $liste) as $val) { |
|
| 562 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 563 | - $n .= ',' . $val; |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - if (strlen($n)) { |
|
| 567 | - $envd[$table] = $n; |
|
| 568 | - } else { |
|
| 569 | - unset($envd[$table]); |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - return $envd; |
|
| 559 | + foreach ($envd as $table => $liste) { |
|
| 560 | + $n = ''; |
|
| 561 | + foreach (explode(',', $liste) as $val) { |
|
| 562 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 563 | + $n .= ',' . $val; |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + if (strlen($n)) { |
|
| 567 | + $envd[$table] = $n; |
|
| 568 | + } else { |
|
| 569 | + unset($envd[$table]); |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + return $envd; |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -589,21 +589,21 @@ discard block |
||
| 589 | 589 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 590 | 590 | **/ |
| 591 | 591 | function match_self($w) { |
| 592 | - if (is_string($w)) { |
|
| 593 | - return false; |
|
| 594 | - } |
|
| 595 | - if (is_array($w)) { |
|
| 596 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 597 | - return $w; |
|
| 598 | - } |
|
| 599 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 600 | - if ($m = match_self($sw)) { |
|
| 601 | - return $m; |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - return false; |
|
| 592 | + if (is_string($w)) { |
|
| 593 | + return false; |
|
| 594 | + } |
|
| 595 | + if (is_array($w)) { |
|
| 596 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 597 | + return $w; |
|
| 598 | + } |
|
| 599 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 600 | + if ($m = match_self($sw)) { |
|
| 601 | + return $m; |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + return false; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -619,16 +619,16 @@ discard block |
||
| 619 | 619 | * est remplacée par son code. |
| 620 | 620 | **/ |
| 621 | 621 | function remplace_sous_requete($w, $sousrequete) { |
| 622 | - if (is_array($w)) { |
|
| 623 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 624 | - return $sousrequete; |
|
| 625 | - } |
|
| 626 | - foreach ($w as $k => $sw) { |
|
| 627 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - return $w; |
|
| 622 | + if (is_array($w)) { |
|
| 623 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 624 | + return $sousrequete; |
|
| 625 | + } |
|
| 626 | + foreach ($w as $k => $sw) { |
|
| 627 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + return $w; |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | /** |
@@ -642,17 +642,17 @@ discard block |
||
| 642 | 642 | * - Conditions avec des sous requêtes |
| 643 | 643 | **/ |
| 644 | 644 | function trouver_sous_requetes($where) { |
| 645 | - $where_simples = []; |
|
| 646 | - $where_sous = []; |
|
| 647 | - foreach ($where as $k => $w) { |
|
| 648 | - if (match_self($w)) { |
|
| 649 | - $where_sous[$k] = $w; |
|
| 650 | - } else { |
|
| 651 | - $where_simples[$k] = $w; |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - return [$where_simples, $where_sous]; |
|
| 645 | + $where_simples = []; |
|
| 646 | + $where_sous = []; |
|
| 647 | + foreach ($where as $k => $w) { |
|
| 648 | + if (match_self($w)) { |
|
| 649 | + $where_sous[$k] = $w; |
|
| 650 | + } else { |
|
| 651 | + $where_simples[$k] = $w; |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + return [$where_simples, $where_sous]; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | |
@@ -678,292 +678,292 @@ discard block |
||
| 678 | 678 | * @return resource |
| 679 | 679 | */ |
| 680 | 680 | function calculer_select( |
| 681 | - $select = [], |
|
| 682 | - $from = [], |
|
| 683 | - $from_type = [], |
|
| 684 | - $where = [], |
|
| 685 | - $join = [], |
|
| 686 | - $groupby = [], |
|
| 687 | - $orderby = [], |
|
| 688 | - $limit = '', |
|
| 689 | - $having = [], |
|
| 690 | - $table = '', |
|
| 691 | - $id = '', |
|
| 692 | - $serveur = '', |
|
| 693 | - $requeter = true |
|
| 681 | + $select = [], |
|
| 682 | + $from = [], |
|
| 683 | + $from_type = [], |
|
| 684 | + $where = [], |
|
| 685 | + $join = [], |
|
| 686 | + $groupby = [], |
|
| 687 | + $orderby = [], |
|
| 688 | + $limit = '', |
|
| 689 | + $having = [], |
|
| 690 | + $table = '', |
|
| 691 | + $id = '', |
|
| 692 | + $serveur = '', |
|
| 693 | + $requeter = true |
|
| 694 | 694 | ) { |
| 695 | 695 | |
| 696 | - // retirer les criteres vides: |
|
| 697 | - // {X ?} avec X absent de l'URL |
|
| 698 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 699 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 700 | - $menage = false; |
|
| 701 | - foreach ($where as $k => $v) { |
|
| 702 | - if (is_array($v)) { |
|
| 703 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 704 | - $op = false; |
|
| 705 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 706 | - $op = false; |
|
| 707 | - } else { |
|
| 708 | - $op = $v[0] ? $v[0] : $v; |
|
| 709 | - } |
|
| 710 | - } else { |
|
| 711 | - $op = $v; |
|
| 712 | - } |
|
| 713 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 714 | - unset($where[$k]); |
|
| 715 | - $menage = true; |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 720 | - $groupby = array_diff($groupby, ['']); |
|
| 721 | - |
|
| 722 | - // remplacer les sous requetes recursives au calcul |
|
| 723 | - list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 724 | - foreach ($where_sous as $k => $w) { |
|
| 725 | - $menage = true; |
|
| 726 | - // on recupere la sous requete |
|
| 727 | - $sous = match_self($w); |
|
| 728 | - if ($sous[0] == 'SELF') { |
|
| 729 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 730 | - array_push($where_simples, $sous[2]); |
|
| 731 | - $wheresub = [ |
|
| 732 | - $sous[2], |
|
| 733 | - '0=0' |
|
| 734 | - ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 735 | - $jsub = $join; |
|
| 736 | - // trouver les jointures utiles a |
|
| 737 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 738 | - // ie L1.objet='article' |
|
| 739 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 740 | - $i = 0; |
|
| 741 | - do { |
|
| 742 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 743 | - [$sous[1] . ' AS id'], |
|
| 744 | - $from, |
|
| 745 | - $from_type, |
|
| 746 | - $wheresub, |
|
| 747 | - $jsub, |
|
| 748 | - [], |
|
| 749 | - [], |
|
| 750 | - '', |
|
| 751 | - $having, |
|
| 752 | - $table, |
|
| 753 | - $id, |
|
| 754 | - $serveur, |
|
| 755 | - false |
|
| 756 | - ) . ')'); |
|
| 757 | - if (!$i) { |
|
| 758 | - $i = 1; |
|
| 759 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 760 | - foreach ($join as $cle => $wj) { |
|
| 761 | - if ( |
|
| 762 | - count($wj) == 4 |
|
| 763 | - and strpos($wherestring, "{$cle}.") !== false |
|
| 764 | - ) { |
|
| 765 | - $i = 0; |
|
| 766 | - $wheresub[] = $wj[3]; |
|
| 767 | - unset($jsub[$cle][3]); |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - } |
|
| 771 | - } while ($i++ < 1); |
|
| 772 | - } |
|
| 773 | - if ($sous[0] == 'SUBSELECT') { |
|
| 774 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 775 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 776 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 777 | - $sous[1], # select |
|
| 778 | - $sous[2], #from |
|
| 779 | - [], #from_type |
|
| 780 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 781 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 782 | - [], #join |
|
| 783 | - $sous[4] ? $sous[4] : [], #groupby |
|
| 784 | - $sous[5] ? $sous[5] : [], #orderby |
|
| 785 | - $sous[6], #limit |
|
| 786 | - $sous[7] ? $sous[7] : [], #having |
|
| 787 | - $table, |
|
| 788 | - $id, |
|
| 789 | - $serveur, |
|
| 790 | - false |
|
| 791 | - ) . ')'); |
|
| 792 | - } |
|
| 793 | - array_pop($where_simples); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - foreach ($having as $k => $v) { |
|
| 797 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 798 | - unset($having[$k]); |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - // Installer les jointures. |
|
| 803 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 804 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 805 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 806 | - |
|
| 807 | - $afrom = []; |
|
| 808 | - $equiv = []; |
|
| 809 | - $k = count($join); |
|
| 810 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 811 | - $cle = $cledef; |
|
| 812 | - // le format de join est : |
|
| 813 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 814 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 815 | - if (count($join[$cle]) == 2) { |
|
| 816 | - $join[$cle][] = $join[$cle][1]; |
|
| 817 | - } |
|
| 818 | - if (count($join[$cle]) == 3) { |
|
| 819 | - $join[$cle][] = ''; |
|
| 820 | - } |
|
| 821 | - list($t, $c, $carr, $and) = $join[$cle]; |
|
| 822 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 823 | - // pour compat avec ancienne convention |
|
| 824 | - if (is_numeric($cle)) { |
|
| 825 | - $cle = "L$k"; |
|
| 826 | - } |
|
| 827 | - $cle_where_lie = "JOIN-$cle"; |
|
| 828 | - if ( |
|
| 829 | - !$menage |
|
| 830 | - or isset($afrom[$cle]) |
|
| 831 | - or calculer_jointnul($cle, $select) |
|
| 832 | - or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 833 | - or calculer_jointnul($cle, $having) |
|
| 834 | - or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 835 | - ) { |
|
| 836 | - // corriger les references non explicites dans select |
|
| 837 | - // ou groupby |
|
| 838 | - foreach ($select as $i => $s) { |
|
| 839 | - if ($s == $c) { |
|
| 840 | - $select[$i] = "$cle.$c AS $c"; |
|
| 841 | - break; |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - foreach ($groupby as $i => $g) { |
|
| 845 | - if ($g == $c) { |
|
| 846 | - $groupby[$i] = "$cle.$c"; |
|
| 847 | - break; |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 851 | - // sans recours a preg_match |
|
| 852 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 853 | - $afrom[$t][$cle] = [ |
|
| 854 | - "\n" . |
|
| 855 | - (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER') . ' JOIN', |
|
| 856 | - $from[$cle], |
|
| 857 | - "AS $cle", |
|
| 858 | - 'ON (', |
|
| 859 | - "$cle.$c", |
|
| 860 | - '=', |
|
| 861 | - "$t.$carr", |
|
| 862 | - ($and ? 'AND ' . $and : '') . |
|
| 863 | - ')' |
|
| 864 | - ]; |
|
| 865 | - if (isset($afrom[$cle])) { |
|
| 866 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 867 | - unset($afrom[$cle]); |
|
| 868 | - } |
|
| 869 | - $equiv[] = $carr; |
|
| 870 | - } else { |
|
| 871 | - unset($join[$cledef]); |
|
| 872 | - if (isset($where_simples[$cle_where_lie])) { |
|
| 873 | - unset($where_simples[$cle_where_lie]); |
|
| 874 | - unset($where[$cle_where_lie]); |
|
| 875 | - } |
|
| 876 | - } |
|
| 877 | - unset($from[$cle]); |
|
| 878 | - $k--; |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - if (count($afrom)) { |
|
| 882 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 883 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 884 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 885 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 886 | - // ou dans |
|
| 887 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 888 | - // qui comporte plusieurs jointures |
|
| 889 | - // ou dans |
|
| 890 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 891 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 892 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 893 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 894 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 895 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 896 | - |
|
| 897 | - $t = key($from); |
|
| 898 | - $c = current($from); |
|
| 899 | - reset($from); |
|
| 900 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 901 | - if ( |
|
| 902 | - !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 903 | - calculer_jointnul($t, $select, $e) or |
|
| 904 | - calculer_jointnul($t, $join, $e) or |
|
| 905 | - calculer_jointnul($t, $where, $e) or |
|
| 906 | - calculer_jointnul($t, $orderby, $e) or |
|
| 907 | - calculer_jointnul($t, $groupby, $e) or |
|
| 908 | - calculer_jointnul($t, $having, $e)) |
|
| 909 | - && count($afrom[$t]) |
|
| 910 | - ) { |
|
| 911 | - $nfrom = reset($afrom[$t]); |
|
| 912 | - $nt = key($afrom[$t]); |
|
| 913 | - unset($from[$t]); |
|
| 914 | - $from[$nt] = $nfrom[1]; |
|
| 915 | - unset($afrom[$t][$nt]); |
|
| 916 | - $afrom[$nt] = $afrom[$t]; |
|
| 917 | - unset($afrom[$t]); |
|
| 918 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 919 | - $t = $nfrom[4]; |
|
| 920 | - $alias = ''; |
|
| 921 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 922 | - $oldcle = explode('.', $nfrom[6]); |
|
| 923 | - $oldcle = end($oldcle); |
|
| 924 | - $newcle = explode('.', $nfrom[4]); |
|
| 925 | - $newcle = end($newcle); |
|
| 926 | - if ($newcle != $oldcle) { |
|
| 927 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 928 | - // reprendre simplement ce AS |
|
| 929 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 930 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 931 | - $alias = ''; |
|
| 932 | - } else { |
|
| 933 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 934 | - } |
|
| 935 | - } |
|
| 936 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 937 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 938 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 939 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 940 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 941 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 942 | - } |
|
| 943 | - $from = reinjecte_joint($afrom, $from); |
|
| 944 | - } |
|
| 945 | - if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 946 | - $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 947 | - $GLOBALS['debug'] = []; |
|
| 948 | - if ($wasdebug) { |
|
| 949 | - $GLOBALS['debug']['debug'] = true; |
|
| 950 | - } |
|
| 951 | - } |
|
| 952 | - $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 953 | - $r = sql_select( |
|
| 954 | - $select, |
|
| 955 | - $from, |
|
| 956 | - $where, |
|
| 957 | - $groupby, |
|
| 958 | - array_filter($orderby), |
|
| 959 | - $limit, |
|
| 960 | - $having, |
|
| 961 | - $serveur, |
|
| 962 | - $requeter |
|
| 963 | - ); |
|
| 964 | - unset($GLOBALS['debug']['aucasou']); |
|
| 965 | - |
|
| 966 | - return $r; |
|
| 696 | + // retirer les criteres vides: |
|
| 697 | + // {X ?} avec X absent de l'URL |
|
| 698 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 699 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 700 | + $menage = false; |
|
| 701 | + foreach ($where as $k => $v) { |
|
| 702 | + if (is_array($v)) { |
|
| 703 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 704 | + $op = false; |
|
| 705 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 706 | + $op = false; |
|
| 707 | + } else { |
|
| 708 | + $op = $v[0] ? $v[0] : $v; |
|
| 709 | + } |
|
| 710 | + } else { |
|
| 711 | + $op = $v; |
|
| 712 | + } |
|
| 713 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 714 | + unset($where[$k]); |
|
| 715 | + $menage = true; |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 720 | + $groupby = array_diff($groupby, ['']); |
|
| 721 | + |
|
| 722 | + // remplacer les sous requetes recursives au calcul |
|
| 723 | + list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 724 | + foreach ($where_sous as $k => $w) { |
|
| 725 | + $menage = true; |
|
| 726 | + // on recupere la sous requete |
|
| 727 | + $sous = match_self($w); |
|
| 728 | + if ($sous[0] == 'SELF') { |
|
| 729 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 730 | + array_push($where_simples, $sous[2]); |
|
| 731 | + $wheresub = [ |
|
| 732 | + $sous[2], |
|
| 733 | + '0=0' |
|
| 734 | + ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 735 | + $jsub = $join; |
|
| 736 | + // trouver les jointures utiles a |
|
| 737 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 738 | + // ie L1.objet='article' |
|
| 739 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 740 | + $i = 0; |
|
| 741 | + do { |
|
| 742 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 743 | + [$sous[1] . ' AS id'], |
|
| 744 | + $from, |
|
| 745 | + $from_type, |
|
| 746 | + $wheresub, |
|
| 747 | + $jsub, |
|
| 748 | + [], |
|
| 749 | + [], |
|
| 750 | + '', |
|
| 751 | + $having, |
|
| 752 | + $table, |
|
| 753 | + $id, |
|
| 754 | + $serveur, |
|
| 755 | + false |
|
| 756 | + ) . ')'); |
|
| 757 | + if (!$i) { |
|
| 758 | + $i = 1; |
|
| 759 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 760 | + foreach ($join as $cle => $wj) { |
|
| 761 | + if ( |
|
| 762 | + count($wj) == 4 |
|
| 763 | + and strpos($wherestring, "{$cle}.") !== false |
|
| 764 | + ) { |
|
| 765 | + $i = 0; |
|
| 766 | + $wheresub[] = $wj[3]; |
|
| 767 | + unset($jsub[$cle][3]); |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | + } while ($i++ < 1); |
|
| 772 | + } |
|
| 773 | + if ($sous[0] == 'SUBSELECT') { |
|
| 774 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 775 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 776 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 777 | + $sous[1], # select |
|
| 778 | + $sous[2], #from |
|
| 779 | + [], #from_type |
|
| 780 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 781 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 782 | + [], #join |
|
| 783 | + $sous[4] ? $sous[4] : [], #groupby |
|
| 784 | + $sous[5] ? $sous[5] : [], #orderby |
|
| 785 | + $sous[6], #limit |
|
| 786 | + $sous[7] ? $sous[7] : [], #having |
|
| 787 | + $table, |
|
| 788 | + $id, |
|
| 789 | + $serveur, |
|
| 790 | + false |
|
| 791 | + ) . ')'); |
|
| 792 | + } |
|
| 793 | + array_pop($where_simples); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + foreach ($having as $k => $v) { |
|
| 797 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 798 | + unset($having[$k]); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + // Installer les jointures. |
|
| 803 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 804 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 805 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 806 | + |
|
| 807 | + $afrom = []; |
|
| 808 | + $equiv = []; |
|
| 809 | + $k = count($join); |
|
| 810 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 811 | + $cle = $cledef; |
|
| 812 | + // le format de join est : |
|
| 813 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 814 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 815 | + if (count($join[$cle]) == 2) { |
|
| 816 | + $join[$cle][] = $join[$cle][1]; |
|
| 817 | + } |
|
| 818 | + if (count($join[$cle]) == 3) { |
|
| 819 | + $join[$cle][] = ''; |
|
| 820 | + } |
|
| 821 | + list($t, $c, $carr, $and) = $join[$cle]; |
|
| 822 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 823 | + // pour compat avec ancienne convention |
|
| 824 | + if (is_numeric($cle)) { |
|
| 825 | + $cle = "L$k"; |
|
| 826 | + } |
|
| 827 | + $cle_where_lie = "JOIN-$cle"; |
|
| 828 | + if ( |
|
| 829 | + !$menage |
|
| 830 | + or isset($afrom[$cle]) |
|
| 831 | + or calculer_jointnul($cle, $select) |
|
| 832 | + or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 833 | + or calculer_jointnul($cle, $having) |
|
| 834 | + or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 835 | + ) { |
|
| 836 | + // corriger les references non explicites dans select |
|
| 837 | + // ou groupby |
|
| 838 | + foreach ($select as $i => $s) { |
|
| 839 | + if ($s == $c) { |
|
| 840 | + $select[$i] = "$cle.$c AS $c"; |
|
| 841 | + break; |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + foreach ($groupby as $i => $g) { |
|
| 845 | + if ($g == $c) { |
|
| 846 | + $groupby[$i] = "$cle.$c"; |
|
| 847 | + break; |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 851 | + // sans recours a preg_match |
|
| 852 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 853 | + $afrom[$t][$cle] = [ |
|
| 854 | + "\n" . |
|
| 855 | + (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER') . ' JOIN', |
|
| 856 | + $from[$cle], |
|
| 857 | + "AS $cle", |
|
| 858 | + 'ON (', |
|
| 859 | + "$cle.$c", |
|
| 860 | + '=', |
|
| 861 | + "$t.$carr", |
|
| 862 | + ($and ? 'AND ' . $and : '') . |
|
| 863 | + ')' |
|
| 864 | + ]; |
|
| 865 | + if (isset($afrom[$cle])) { |
|
| 866 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 867 | + unset($afrom[$cle]); |
|
| 868 | + } |
|
| 869 | + $equiv[] = $carr; |
|
| 870 | + } else { |
|
| 871 | + unset($join[$cledef]); |
|
| 872 | + if (isset($where_simples[$cle_where_lie])) { |
|
| 873 | + unset($where_simples[$cle_where_lie]); |
|
| 874 | + unset($where[$cle_where_lie]); |
|
| 875 | + } |
|
| 876 | + } |
|
| 877 | + unset($from[$cle]); |
|
| 878 | + $k--; |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + if (count($afrom)) { |
|
| 882 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 883 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 884 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 885 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 886 | + // ou dans |
|
| 887 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 888 | + // qui comporte plusieurs jointures |
|
| 889 | + // ou dans |
|
| 890 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 891 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 892 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 893 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 894 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 895 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 896 | + |
|
| 897 | + $t = key($from); |
|
| 898 | + $c = current($from); |
|
| 899 | + reset($from); |
|
| 900 | + $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 901 | + if ( |
|
| 902 | + !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 903 | + calculer_jointnul($t, $select, $e) or |
|
| 904 | + calculer_jointnul($t, $join, $e) or |
|
| 905 | + calculer_jointnul($t, $where, $e) or |
|
| 906 | + calculer_jointnul($t, $orderby, $e) or |
|
| 907 | + calculer_jointnul($t, $groupby, $e) or |
|
| 908 | + calculer_jointnul($t, $having, $e)) |
|
| 909 | + && count($afrom[$t]) |
|
| 910 | + ) { |
|
| 911 | + $nfrom = reset($afrom[$t]); |
|
| 912 | + $nt = key($afrom[$t]); |
|
| 913 | + unset($from[$t]); |
|
| 914 | + $from[$nt] = $nfrom[1]; |
|
| 915 | + unset($afrom[$t][$nt]); |
|
| 916 | + $afrom[$nt] = $afrom[$t]; |
|
| 917 | + unset($afrom[$t]); |
|
| 918 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 919 | + $t = $nfrom[4]; |
|
| 920 | + $alias = ''; |
|
| 921 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 922 | + $oldcle = explode('.', $nfrom[6]); |
|
| 923 | + $oldcle = end($oldcle); |
|
| 924 | + $newcle = explode('.', $nfrom[4]); |
|
| 925 | + $newcle = end($newcle); |
|
| 926 | + if ($newcle != $oldcle) { |
|
| 927 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 928 | + // reprendre simplement ce AS |
|
| 929 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 930 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 931 | + $alias = ''; |
|
| 932 | + } else { |
|
| 933 | + $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 934 | + } |
|
| 935 | + } |
|
| 936 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 937 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 938 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 939 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 940 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 941 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 942 | + } |
|
| 943 | + $from = reinjecte_joint($afrom, $from); |
|
| 944 | + } |
|
| 945 | + if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 946 | + $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 947 | + $GLOBALS['debug'] = []; |
|
| 948 | + if ($wasdebug) { |
|
| 949 | + $GLOBALS['debug']['debug'] = true; |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 953 | + $r = sql_select( |
|
| 954 | + $select, |
|
| 955 | + $from, |
|
| 956 | + $where, |
|
| 957 | + $groupby, |
|
| 958 | + array_filter($orderby), |
|
| 959 | + $limit, |
|
| 960 | + $having, |
|
| 961 | + $serveur, |
|
| 962 | + $requeter |
|
| 963 | + ); |
|
| 964 | + unset($GLOBALS['debug']['aucasou']); |
|
| 965 | + |
|
| 966 | + return $r; |
|
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | /** |
@@ -974,20 +974,20 @@ discard block |
||
| 974 | 974 | * @return string |
| 975 | 975 | */ |
| 976 | 976 | function calculer_where_to_string($v, $join = 'AND') { |
| 977 | - if (empty($v)) { |
|
| 978 | - return ''; |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - if (!is_array($v)) { |
|
| 982 | - return $v; |
|
| 983 | - } else { |
|
| 984 | - $exp = ''; |
|
| 985 | - if (strtoupper($join) === 'AND') { |
|
| 986 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 987 | - } else { |
|
| 988 | - return $exp . join($join, $v); |
|
| 989 | - } |
|
| 990 | - } |
|
| 977 | + if (empty($v)) { |
|
| 978 | + return ''; |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + if (!is_array($v)) { |
|
| 982 | + return $v; |
|
| 983 | + } else { |
|
| 984 | + $exp = ''; |
|
| 985 | + if (strtoupper($join) === 'AND') { |
|
| 986 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 987 | + } else { |
|
| 988 | + return $exp . join($join, $v); |
|
| 989 | + } |
|
| 990 | + } |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | |
@@ -995,62 +995,62 @@ discard block |
||
| 995 | 995 | |
| 996 | 996 | // https://code.spip.net/@calculer_jointnul |
| 997 | 997 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 998 | - if (!is_array($exp)) { |
|
| 999 | - if ($equiv) { |
|
| 1000 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1004 | - } else { |
|
| 1005 | - foreach ($exp as $v) { |
|
| 1006 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1007 | - return true; |
|
| 1008 | - } |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - return false; |
|
| 1012 | - } |
|
| 998 | + if (!is_array($exp)) { |
|
| 999 | + if ($equiv) { |
|
| 1000 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1004 | + } else { |
|
| 1005 | + foreach ($exp as $v) { |
|
| 1006 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1007 | + return true; |
|
| 1008 | + } |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + return false; |
|
| 1012 | + } |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | // https://code.spip.net/@reinjecte_joint |
| 1016 | 1016 | function reinjecte_joint($afrom, $from) { |
| 1017 | - $from_synth = []; |
|
| 1018 | - foreach ($from as $k => $v) { |
|
| 1019 | - $from_synth[$k] = $from[$k]; |
|
| 1020 | - if (isset($afrom[$k])) { |
|
| 1021 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1022 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1023 | - } |
|
| 1024 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1025 | - unset($afrom[$k]); |
|
| 1026 | - } |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - return $from_synth; |
|
| 1017 | + $from_synth = []; |
|
| 1018 | + foreach ($from as $k => $v) { |
|
| 1019 | + $from_synth[$k] = $from[$k]; |
|
| 1020 | + if (isset($afrom[$k])) { |
|
| 1021 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1022 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1023 | + } |
|
| 1024 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1025 | + unset($afrom[$k]); |
|
| 1026 | + } |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + return $from_synth; |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | // https://code.spip.net/@remplacer_jointnul |
| 1033 | 1033 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1034 | - if (!is_array($exp)) { |
|
| 1035 | - return preg_replace($equiv, $cle, $exp); |
|
| 1036 | - } else { |
|
| 1037 | - foreach ($exp as $k => $v) { |
|
| 1038 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - return $exp; |
|
| 1042 | - } |
|
| 1034 | + if (!is_array($exp)) { |
|
| 1035 | + return preg_replace($equiv, $cle, $exp); |
|
| 1036 | + } else { |
|
| 1037 | + foreach ($exp as $k => $v) { |
|
| 1038 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + return $exp; |
|
| 1042 | + } |
|
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | // calcul du nom du squelette |
| 1046 | 1046 | // https://code.spip.net/@calculer_nom_fonction_squel |
| 1047 | 1047 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', $connect = '') { |
| 1048 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1049 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1050 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - return $mime_type |
|
| 1054 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1055 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1048 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1049 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1050 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + return $mime_type |
|
| 1054 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1055 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1056 | 1056 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $GLOBALS['debug_objets']['courant'] = $nom; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true).$nom.'.php'; |
|
| 58 | 58 | |
| 59 | 59 | // si squelette est deja compile et perenne, le charger |
| 60 | 60 | if (!squelette_obsolete($phpfile, $source)) { |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | #} |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | + if (file_exists($lib = $squelette.'_fonctions'.'.php')) { |
|
| 71 | 71 | include_once $lib; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | eval("return true; $f ;"); |
| 96 | 96 | } catch (\ParseError $e) { |
| 97 | 97 | // Code syntaxiquement faux (critere etc mal programme') |
| 98 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 98 | + $msg = _T('zbug_erreur_compilation').' | Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 99 | 99 | erreur_squelette($msg, $boucle); |
| 100 | 100 | // continuer pour trouver d'autres fautes eventuelles |
| 101 | 101 | // mais prevenir que c'est mort |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
| 125 | 125 | // Tracer ce qui vient d'etre compile |
| 126 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 126 | + $GLOBALS['debug_objets']['code'][$nom.'tout'] = $code; |
|
| 127 | 127 | |
| 128 | 128 | // si c'est ce que demande le debusqueur, lui passer la main |
| 129 | 129 | if ( |
@@ -146,13 +146,13 @@ discard block |
||
| 146 | 146 | $code = " |
| 147 | 147 | /* |
| 148 | 148 | * Squelette : $sourcefile |
| 149 | - * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
|
| 150 | - * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
|
| 151 | - * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
|
| 149 | + * Date : ".gmdate('D, d M Y H:i:s', @filemtime($sourcefile)).' GMT |
|
| 150 | + * Compile : ' . gmdate('D, d M Y H:i:s', time()).' GMT |
|
| 151 | + * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : '.$noms)).' |
|
| 152 | 152 | */ '; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 155 | + $code = '<'."?php\n".$code.join('', $boucles)."\n?".'>'; |
|
| 156 | 156 | if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
| 157 | 157 | ecrire_fichier($phpfile, $code); |
| 158 | 158 | } |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 217 | 217 | |
| 218 | 218 | if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
| 219 | - $headers[$j] .= '|' . $r[3]; |
|
| 219 | + $headers[$j] .= '|'.$r[3]; |
|
| 220 | 220 | } else { |
| 221 | 221 | $headers[$j] = $r[3]; |
| 222 | 222 | } |
@@ -224,10 +224,10 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | // S'agit-il d'un resultat constant ou contenant du code php |
| 226 | 226 | $process_ins = ( |
| 227 | - strpos($corps, '<' . '?') === false |
|
| 227 | + strpos($corps, '<'.'?') === false |
|
| 228 | 228 | or |
| 229 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 229 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 230 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 231 | 231 | ) |
| 232 | 232 | ? 'html' |
| 233 | 233 | : 'php'; |
@@ -256,10 +256,10 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | if ($process_ins == 'html') { |
| 258 | 258 | $skel['process_ins'] = ( |
| 259 | - strpos($corps, '<' . '?') === false |
|
| 259 | + strpos($corps, '<'.'?') === false |
|
| 260 | 260 | or |
| 261 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 261 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 262 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 263 | 263 | ) |
| 264 | 264 | ? 'html' |
| 265 | 265 | : 'php'; |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | // |
| 278 | 278 | |
| 279 | 279 | /** Code PHP pour inclure une balise dynamique à l'exécution d'une page */ |
| 280 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 280 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 281 | 281 | include_once("%s"); |
| 282 | 282 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 283 | 283 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | // pas de lien symbolique sous Windows |
| 309 | 309 | and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
| 310 | 310 | ) { |
| 311 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | + $file = './" . _DIR_RACINE . "'.$file; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | $lang = $context_compil[4]; |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | $args = array_map('argumenter_squelette', $args); |
| 320 | 320 | if (!empty($context_compil['appel_php_depuis_modele'])) { |
| 321 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | + $args[0] = 'arguments_balise_dyn_depuis_modele('.$args[0].')'; |
|
| 322 | 322 | } |
| 323 | 323 | $args = join(', ', $args); |
| 324 | 324 | |
@@ -352,14 +352,14 @@ discard block |
||
| 352 | 352 | if (is_object($v)) { |
| 353 | 353 | return var_export($v, true); |
| 354 | 354 | } elseif (!is_array($v)) { |
| 355 | - return "'" . texte_script($v) . "'"; |
|
| 355 | + return "'".texte_script($v)."'"; |
|
| 356 | 356 | } else { |
| 357 | 357 | $out = []; |
| 358 | 358 | foreach ($v as $k => $val) { |
| 359 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - return 'array(' . join(', ', $out) . ')'; |
|
| 362 | + return 'array('.join(', ', $out).')'; |
|
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | 365 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // Y a-t-il une fonction de traitement des arguments ? |
| 440 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 440 | + $f = 'balise_'.$nom_balise.'_stat'; |
|
| 441 | 441 | |
| 442 | 442 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 443 | 443 | |
@@ -447,18 +447,18 @@ discard block |
||
| 447 | 447 | |
| 448 | 448 | // verifier que la fonction dyn est la, |
| 449 | 449 | // sinon se replier sur la generique si elle existe |
| 450 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 450 | + if (!function_exists('balise_'.$nom_balise.'_dyn')) { |
|
| 451 | 451 | if ( |
| 452 | 452 | $balise_generique = chercher_balise_generique($nom) |
| 453 | 453 | and $nom_balise_generique = $balise_generique['nom_generique'] |
| 454 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 455 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 454 | + and $file = include_spip('balise/'.strtolower($nom_balise_generique)) |
|
| 455 | + and function_exists('balise_'.$nom_balise_generique.'_dyn') |
|
| 456 | 456 | ) { |
| 457 | 457 | // et lui injecter en premier arg le nom de la balise |
| 458 | 458 | array_unshift($r, $nom); |
| 459 | 459 | $nom_balise = $nom_balise_generique; |
| 460 | 460 | if (!_DIR_RESTREINT) { |
| 461 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 461 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 462 | 462 | } |
| 463 | 463 | } else { |
| 464 | 464 | $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | $n = ''; |
| 561 | 561 | foreach (explode(',', $liste) as $val) { |
| 562 | 562 | if ($a = intval($val) and $val === strval($a)) { |
| 563 | - $n .= ',' . $val; |
|
| 563 | + $n .= ','.$val; |
|
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | if (strlen($n)) { |
@@ -739,8 +739,8 @@ discard block |
||
| 739 | 739 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 740 | 740 | $i = 0; |
| 741 | 741 | do { |
| 742 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 743 | - [$sous[1] . ' AS id'], |
|
| 742 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 743 | + [$sous[1].' AS id'], |
|
| 744 | 744 | $from, |
| 745 | 745 | $from_type, |
| 746 | 746 | $wheresub, |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | $id, |
| 754 | 754 | $serveur, |
| 755 | 755 | false |
| 756 | - ) . ')'); |
|
| 756 | + ).')'); |
|
| 757 | 757 | if (!$i) { |
| 758 | 758 | $i = 1; |
| 759 | 759 | $wherestring = calculer_where_to_string($where[$k]); |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | if ($sous[0] == 'SUBSELECT') { |
| 774 | 774 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 775 | 775 | array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
| 776 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 776 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 777 | 777 | $sous[1], # select |
| 778 | 778 | $sous[2], #from |
| 779 | 779 | [], #from_type |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | $id, |
| 789 | 789 | $serveur, |
| 790 | 790 | false |
| 791 | - ) . ')'); |
|
| 791 | + ).')'); |
|
| 792 | 792 | } |
| 793 | 793 | array_pop($where_simples); |
| 794 | 794 | } |
@@ -851,15 +851,15 @@ discard block |
||
| 851 | 851 | // sans recours a preg_match |
| 852 | 852 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 853 | 853 | $afrom[$t][$cle] = [ |
| 854 | - "\n" . |
|
| 855 | - (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER') . ' JOIN', |
|
| 854 | + "\n". |
|
| 855 | + (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER').' JOIN', |
|
| 856 | 856 | $from[$cle], |
| 857 | 857 | "AS $cle", |
| 858 | 858 | 'ON (', |
| 859 | 859 | "$cle.$c", |
| 860 | 860 | '=', |
| 861 | 861 | "$t.$carr", |
| 862 | - ($and ? 'AND ' . $and : '') . |
|
| 862 | + ($and ? 'AND '.$and : ''). |
|
| 863 | 863 | ')' |
| 864 | 864 | ]; |
| 865 | 865 | if (isset($afrom[$cle])) { |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | $t = key($from); |
| 898 | 898 | $c = current($from); |
| 899 | 899 | reset($from); |
| 900 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 900 | + $e = '/\b('."$t\\.".join('|'.$t.'\.', $equiv).')\b/'; |
|
| 901 | 901 | if ( |
| 902 | 902 | !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
| 903 | 903 | calculer_jointnul($t, $select, $e) or |
@@ -915,7 +915,7 @@ discard block |
||
| 915 | 915 | unset($afrom[$t][$nt]); |
| 916 | 916 | $afrom[$nt] = $afrom[$t]; |
| 917 | 917 | unset($afrom[$t]); |
| 918 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 918 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 919 | 919 | $t = $nfrom[4]; |
| 920 | 920 | $alias = ''; |
| 921 | 921 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
@@ -926,14 +926,14 @@ discard block |
||
| 926 | 926 | if ($newcle != $oldcle) { |
| 927 | 927 | // si l'ancienne cle etait deja dans le select avec un AS |
| 928 | 928 | // reprendre simplement ce AS |
| 929 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 929 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 930 | 930 | if (preg_match($as, implode(',', $select), $m)) { |
| 931 | 931 | $alias = ''; |
| 932 | 932 | } else { |
| 933 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 933 | + $alias = ', '.$nfrom[4]." AS $oldcle"; |
|
| 934 | 934 | } |
| 935 | 935 | } |
| 936 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 936 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 937 | 937 | $join = remplacer_jointnul($t, $join, $e); |
| 938 | 938 | $where = remplacer_jointnul($t, $where, $e); |
| 939 | 939 | $having = remplacer_jointnul($t, $having, $e); |
@@ -983,9 +983,9 @@ discard block |
||
| 983 | 983 | } else { |
| 984 | 984 | $exp = ''; |
| 985 | 985 | if (strtoupper($join) === 'AND') { |
| 986 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 986 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 987 | 987 | } else { |
| 988 | - return $exp . join($join, $v); |
|
| 988 | + return $exp.join($join, $v); |
|
| 989 | 989 | } |
| 990 | 990 | } |
| 991 | 991 | } |
@@ -1051,6 +1051,6 @@ discard block |
||
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | return $mime_type |
| 1054 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1055 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1054 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)).'_' |
|
| 1055 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 1056 | 1056 | } |
@@ -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 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
@@ -39,59 +39,59 @@ discard block |
||
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | 41 | function public_styliser_dist($fond, $contexte, $lang = '', $connect = '') { |
| 42 | - static $styliser_par_z; |
|
| 43 | - |
|
| 44 | - // s'assurer que le fond est licite |
|
| 45 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | - if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | - $fond = '404'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | - $modele = substr($fond, 8); |
|
| 52 | - $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | - $fond = "modeles/$modele"; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | - $id_rubrique = 0; |
|
| 58 | - // Chercher le fond qui va servir de squelette |
|
| 59 | - if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | - list($id_rubrique, $lang) = $r; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // trouver un squelette du nom demande |
|
| 64 | - // ne rien dire si on ne trouve pas, |
|
| 65 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | - $squelette = trouver_fond($fond, '', true); |
|
| 68 | - $ext = $squelette['extension']; |
|
| 69 | - |
|
| 70 | - $flux = [ |
|
| 71 | - 'args' => [ |
|
| 72 | - 'id_rubrique' => $id_rubrique, |
|
| 73 | - 'ext' => $ext, |
|
| 74 | - 'fond' => $fond, |
|
| 75 | - 'lang' => $lang, |
|
| 76 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | - 'connect' => $connect |
|
| 78 | - ], |
|
| 79 | - 'data' => $squelette['fond'], |
|
| 80 | - ]; |
|
| 81 | - |
|
| 82 | - if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | - if (!$styliser_par_z) { |
|
| 84 | - $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | - } |
|
| 86 | - $flux = $styliser_par_z($flux); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $flux = styliser_par_objets($flux); |
|
| 90 | - |
|
| 91 | - // pipeline styliser |
|
| 92 | - $squelette = pipeline('styliser', $flux); |
|
| 93 | - |
|
| 94 | - return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 42 | + static $styliser_par_z; |
|
| 43 | + |
|
| 44 | + // s'assurer que le fond est licite |
|
| 45 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | + if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | + $fond = '404'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | + $modele = substr($fond, 8); |
|
| 52 | + $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | + $fond = "modeles/$modele"; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | + $id_rubrique = 0; |
|
| 58 | + // Chercher le fond qui va servir de squelette |
|
| 59 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | + list($id_rubrique, $lang) = $r; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // trouver un squelette du nom demande |
|
| 64 | + // ne rien dire si on ne trouve pas, |
|
| 65 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | + $squelette = trouver_fond($fond, '', true); |
|
| 68 | + $ext = $squelette['extension']; |
|
| 69 | + |
|
| 70 | + $flux = [ |
|
| 71 | + 'args' => [ |
|
| 72 | + 'id_rubrique' => $id_rubrique, |
|
| 73 | + 'ext' => $ext, |
|
| 74 | + 'fond' => $fond, |
|
| 75 | + 'lang' => $lang, |
|
| 76 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | + 'connect' => $connect |
|
| 78 | + ], |
|
| 79 | + 'data' => $squelette['fond'], |
|
| 80 | + ]; |
|
| 81 | + |
|
| 82 | + if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | + if (!$styliser_par_z) { |
|
| 84 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | + } |
|
| 86 | + $flux = $styliser_par_z($flux); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $flux = styliser_par_objets($flux); |
|
| 90 | + |
|
| 91 | + // pipeline styliser |
|
| 92 | + $squelette = pipeline('styliser', $flux); |
|
| 93 | + |
|
| 94 | + return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -110,32 +110,32 @@ discard block |
||
| 110 | 110 | * Données du pipeline styliser |
| 111 | 111 | **/ |
| 112 | 112 | function styliser_par_objets($flux) { |
| 113 | - if ( |
|
| 114 | - test_espace_prive() |
|
| 115 | - and !$squelette = $flux['data'] |
|
| 116 | - and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | - and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | - ) { |
|
| 119 | - if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | - $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | - $table_sql = table_objet_sql($table); |
|
| 122 | - $objets = lister_tables_objets_sql(); |
|
| 123 | - if (isset($objets[$table_sql])) { |
|
| 124 | - $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | - $type = substr($flux['args']['fond'], 21); |
|
| 129 | - $table = table_objet($type); |
|
| 130 | - $table_sql = table_objet_sql($table); |
|
| 131 | - $objets = lister_tables_objets_sql(); |
|
| 132 | - if (isset($objets[$table_sql])) { |
|
| 133 | - $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $flux; |
|
| 113 | + if ( |
|
| 114 | + test_espace_prive() |
|
| 115 | + and !$squelette = $flux['data'] |
|
| 116 | + and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | + and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | + ) { |
|
| 119 | + if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | + $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | + $table_sql = table_objet_sql($table); |
|
| 122 | + $objets = lister_tables_objets_sql(); |
|
| 123 | + if (isset($objets[$table_sql])) { |
|
| 124 | + $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | + $type = substr($flux['args']['fond'], 21); |
|
| 129 | + $table = table_objet($type); |
|
| 130 | + $table_sql = table_objet_sql($table); |
|
| 131 | + $objets = lister_tables_objets_sql(); |
|
| 132 | + if (isset($objets[$table_sql])) { |
|
| 133 | + $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $flux; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,50 +151,50 @@ discard block |
||
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | 153 | function quete_rubrique_fond($contexte) { |
| 154 | - static $liste_objets = null; |
|
| 155 | - static $quete = []; |
|
| 156 | - if (is_null($liste_objets)) { |
|
| 157 | - $liste_objets = []; |
|
| 158 | - include_spip('inc/urls'); |
|
| 159 | - include_spip('public/quete'); |
|
| 160 | - $l = urls_liste_objets(false); |
|
| 161 | - // placer la rubrique en tete des objets |
|
| 162 | - $l = array_diff($l, ['rubrique']); |
|
| 163 | - array_unshift($l, 'rubrique'); |
|
| 164 | - foreach ($l as $objet) { |
|
| 165 | - $id = id_table_objet($objet); |
|
| 166 | - if (!isset($liste_objets[$id])) { |
|
| 167 | - $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | - if (!count($c)) { |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $c = array_map('intval', $c); |
|
| 177 | - $s = serialize($c); |
|
| 178 | - if (isset($quete[$s])) { |
|
| 179 | - return $quete[$s]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | - unset($c['id_rubrique']); |
|
| 184 | - $c = ['id_rubrique' => $r] + $c; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - foreach ($c as $_id => $id) { |
|
| 188 | - if ( |
|
| 189 | - $id |
|
| 190 | - and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | - ) { |
|
| 192 | - $lang = isset($row['lang']) ? $row['lang'] : ''; |
|
| 193 | - if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | - return $quete[$s] = [$id, $lang]; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $quete[$s] = false; |
|
| 154 | + static $liste_objets = null; |
|
| 155 | + static $quete = []; |
|
| 156 | + if (is_null($liste_objets)) { |
|
| 157 | + $liste_objets = []; |
|
| 158 | + include_spip('inc/urls'); |
|
| 159 | + include_spip('public/quete'); |
|
| 160 | + $l = urls_liste_objets(false); |
|
| 161 | + // placer la rubrique en tete des objets |
|
| 162 | + $l = array_diff($l, ['rubrique']); |
|
| 163 | + array_unshift($l, 'rubrique'); |
|
| 164 | + foreach ($l as $objet) { |
|
| 165 | + $id = id_table_objet($objet); |
|
| 166 | + if (!isset($liste_objets[$id])) { |
|
| 167 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | + if (!count($c)) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $c = array_map('intval', $c); |
|
| 177 | + $s = serialize($c); |
|
| 178 | + if (isset($quete[$s])) { |
|
| 179 | + return $quete[$s]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | + unset($c['id_rubrique']); |
|
| 184 | + $c = ['id_rubrique' => $r] + $c; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + foreach ($c as $_id => $id) { |
|
| 188 | + if ( |
|
| 189 | + $id |
|
| 190 | + and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | + ) { |
|
| 192 | + $lang = isset($row['lang']) ? $row['lang'] : ''; |
|
| 193 | + if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | + return $quete[$s] = [$id, $lang]; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $quete[$s] = false; |
|
| 200 | 200 | } |
@@ -19,10 +19,10 @@ |
||
| 19 | 19 | * @package SPIP\Core\SQL\Upgrade |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][2021021800] = [ |
| 26 | - ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | - ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 26 | + ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | + ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 28 | 28 | ]; |
@@ -23,6 +23,6 @@ |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][2021021800] = [ |
| 26 | - ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | - ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 26 | + ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL"], |
|
| 27 | + ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL"], |
|
| 28 | 28 | ]; |
@@ -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,18 +18,18 @@ 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'][16428] = [ |
| 26 | - ['maj_liens', 'auteur'], // creer la table liens |
|
| 27 | - ['maj_liens', 'auteur', 'article'], |
|
| 28 | - ['sql_drop_table', 'spip_auteurs_articles'], |
|
| 29 | - ['maj_liens', 'auteur', 'rubrique'], |
|
| 30 | - ['sql_drop_table', 'spip_auteurs_rubriques'], |
|
| 31 | - ['maj_liens', 'auteur', 'message'], |
|
| 32 | - ['sql_drop_table', 'spip_auteurs_messages'], |
|
| 26 | + ['maj_liens', 'auteur'], // creer la table liens |
|
| 27 | + ['maj_liens', 'auteur', 'article'], |
|
| 28 | + ['sql_drop_table', 'spip_auteurs_articles'], |
|
| 29 | + ['maj_liens', 'auteur', 'rubrique'], |
|
| 30 | + ['sql_drop_table', 'spip_auteurs_rubriques'], |
|
| 31 | + ['maj_liens', 'auteur', 'message'], |
|
| 32 | + ['sql_drop_table', 'spip_auteurs_messages'], |
|
| 33 | 33 | ]; |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -55,89 +55,89 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function maj_liens($pivot, $l = '') { |
| 57 | 57 | |
| 58 | - @define('_LOG_FILTRE_GRAVITE', 8); |
|
| 59 | - |
|
| 60 | - $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
|
| 61 | - |
|
| 62 | - $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
|
| 63 | - $pivots = (isset($exceptions_pluriel[$pivot]) ? $exceptions_pluriel[$pivot] : $pivot . 's'); |
|
| 64 | - $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | - $id_pivot = 'id_' . $pivot; |
|
| 66 | - // Creer spip_auteurs_liens |
|
| 67 | - global $tables_auxiliaires; |
|
| 68 | - if (!$l) { |
|
| 69 | - include_spip('base/auxiliaires'); |
|
| 70 | - include_spip('base/create'); |
|
| 71 | - creer_ou_upgrader_table($liens, $tables_auxiliaires[$liens], false); |
|
| 72 | - } else { |
|
| 73 | - // Preparer |
|
| 74 | - $l = preg_replace(',[^\w],', '', $l); // securite |
|
| 75 | - $primary = "id_$l"; |
|
| 76 | - $objet = ($l == 'syndic' ? 'site' : $l); |
|
| 77 | - $ls = (isset($exceptions_pluriel[$l]) ? $exceptions_pluriel[$l] : $l . 's'); |
|
| 78 | - $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 79 | - $pool = 400; |
|
| 80 | - |
|
| 81 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 82 | - if (!$desc = $trouver_table($ancienne_table)) { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // securite pour ne pas perdre de donnees |
|
| 87 | - if (!$trouver_table($liens)) { |
|
| 88 | - return; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $champs = $desc['field']; |
|
| 92 | - if (isset($champs['maj'])) { |
|
| 93 | - unset($champs['maj']); |
|
| 94 | - } |
|
| 95 | - if (isset($champs[$primary])) { |
|
| 96 | - unset($champs[$primary]); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $champs = array_keys($champs); |
|
| 100 | - // ne garder que les champs qui existent sur la table destination |
|
| 101 | - if ($desc_cible = $trouver_table($liens)) { |
|
| 102 | - $champs = array_intersect($champs, array_keys($desc_cible['field'])); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $champs[] = "$primary as id_objet"; |
|
| 106 | - $champs[] = "'$objet' as objet"; |
|
| 107 | - $champs = implode(', ', $champs); |
|
| 108 | - |
|
| 109 | - // Recopier les donnees |
|
| 110 | - $sub_pool = 100; |
|
| 111 | - while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
|
| 112 | - $insert = []; |
|
| 113 | - foreach ($ids as $id) { |
|
| 114 | - $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | - while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | - $n += count($t); |
|
| 117 | - // empiler en s'assurant a minima de l'unicite |
|
| 118 | - while ($r = array_shift($t)) { |
|
| 119 | - $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 120 | - } |
|
| 121 | - if (count($insert) >= $sub_pool) { |
|
| 122 | - maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 123 | - $insert = []; |
|
| 124 | - } |
|
| 125 | - // si timeout, sortir, la relance nous ramenera dans cette fonction |
|
| 126 | - // et on verifiera/repartira de la |
|
| 127 | - if (time() >= _TIME_OUT) { |
|
| 128 | - return; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (time() >= _TIME_OUT) { |
|
| 132 | - return; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if (count($insert)) { |
|
| 136 | - maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 137 | - } |
|
| 138 | - sql_delete($ancienne_table, sql_in($primary, $ids)); |
|
| 139 | - } |
|
| 140 | - } |
|
| 58 | + @define('_LOG_FILTRE_GRAVITE', 8); |
|
| 59 | + |
|
| 60 | + $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
|
| 61 | + |
|
| 62 | + $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
|
| 63 | + $pivots = (isset($exceptions_pluriel[$pivot]) ? $exceptions_pluriel[$pivot] : $pivot . 's'); |
|
| 64 | + $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | + $id_pivot = 'id_' . $pivot; |
|
| 66 | + // Creer spip_auteurs_liens |
|
| 67 | + global $tables_auxiliaires; |
|
| 68 | + if (!$l) { |
|
| 69 | + include_spip('base/auxiliaires'); |
|
| 70 | + include_spip('base/create'); |
|
| 71 | + creer_ou_upgrader_table($liens, $tables_auxiliaires[$liens], false); |
|
| 72 | + } else { |
|
| 73 | + // Preparer |
|
| 74 | + $l = preg_replace(',[^\w],', '', $l); // securite |
|
| 75 | + $primary = "id_$l"; |
|
| 76 | + $objet = ($l == 'syndic' ? 'site' : $l); |
|
| 77 | + $ls = (isset($exceptions_pluriel[$l]) ? $exceptions_pluriel[$l] : $l . 's'); |
|
| 78 | + $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 79 | + $pool = 400; |
|
| 80 | + |
|
| 81 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 82 | + if (!$desc = $trouver_table($ancienne_table)) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // securite pour ne pas perdre de donnees |
|
| 87 | + if (!$trouver_table($liens)) { |
|
| 88 | + return; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $champs = $desc['field']; |
|
| 92 | + if (isset($champs['maj'])) { |
|
| 93 | + unset($champs['maj']); |
|
| 94 | + } |
|
| 95 | + if (isset($champs[$primary])) { |
|
| 96 | + unset($champs[$primary]); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $champs = array_keys($champs); |
|
| 100 | + // ne garder que les champs qui existent sur la table destination |
|
| 101 | + if ($desc_cible = $trouver_table($liens)) { |
|
| 102 | + $champs = array_intersect($champs, array_keys($desc_cible['field'])); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $champs[] = "$primary as id_objet"; |
|
| 106 | + $champs[] = "'$objet' as objet"; |
|
| 107 | + $champs = implode(', ', $champs); |
|
| 108 | + |
|
| 109 | + // Recopier les donnees |
|
| 110 | + $sub_pool = 100; |
|
| 111 | + while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
|
| 112 | + $insert = []; |
|
| 113 | + foreach ($ids as $id) { |
|
| 114 | + $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | + while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | + $n += count($t); |
|
| 117 | + // empiler en s'assurant a minima de l'unicite |
|
| 118 | + while ($r = array_shift($t)) { |
|
| 119 | + $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 120 | + } |
|
| 121 | + if (count($insert) >= $sub_pool) { |
|
| 122 | + maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 123 | + $insert = []; |
|
| 124 | + } |
|
| 125 | + // si timeout, sortir, la relance nous ramenera dans cette fonction |
|
| 126 | + // et on verifiera/repartira de la |
|
| 127 | + if (time() >= _TIME_OUT) { |
|
| 128 | + return; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (time() >= _TIME_OUT) { |
|
| 132 | + return; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if (count($insert)) { |
|
| 136 | + maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 137 | + } |
|
| 138 | + sql_delete($ancienne_table, sql_in($primary, $ids)); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -151,86 +151,86 @@ discard block |
||
| 151 | 151 | * @return void |
| 152 | 152 | **/ |
| 153 | 153 | function maj_liens_insertq_multi_check($table, $couples, $desc = []) { |
| 154 | - $n_before = sql_countsel($table); |
|
| 155 | - sql_insertq_multi($table, $couples, $desc); |
|
| 156 | - $n_after = sql_countsel($table); |
|
| 157 | - if (($n_after - $n_before) == count($couples)) { |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - // si ecart, on recommence l'insertion ligne par ligne... |
|
| 161 | - // moins rapide mais secure : seul le couple en doublon echouera, et non toute la serie |
|
| 162 | - foreach ($couples as $c) { |
|
| 163 | - sql_insertq($table, $c, $desc); |
|
| 164 | - } |
|
| 154 | + $n_before = sql_countsel($table); |
|
| 155 | + sql_insertq_multi($table, $couples, $desc); |
|
| 156 | + $n_after = sql_countsel($table); |
|
| 157 | + if (($n_after - $n_before) == count($couples)) { |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + // si ecart, on recommence l'insertion ligne par ligne... |
|
| 161 | + // moins rapide mais secure : seul le couple en doublon echouera, et non toute la serie |
|
| 162 | + foreach ($couples as $c) { |
|
| 163 | + sql_insertq($table, $c, $desc); |
|
| 164 | + } |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $GLOBALS['maj'][17311] = [ |
| 168 | - [ |
|
| 169 | - 'ecrire_meta', |
|
| 170 | - 'multi_objets', |
|
| 171 | - implode( |
|
| 172 | - ',', |
|
| 173 | - array_diff( |
|
| 174 | - [ |
|
| 175 | - (isset($GLOBALS['meta']['multi_rubriques']) and $GLOBALS['meta']['multi_rubriques'] == 'oui') |
|
| 176 | - ? 'spip_rubriques' : '', |
|
| 177 | - (isset($GLOBALS['meta']['multi_articles']) and $GLOBALS['meta']['multi_articles'] == 'oui') |
|
| 178 | - ? 'spip_articles' : '' |
|
| 179 | - ], |
|
| 180 | - [''] |
|
| 181 | - ) |
|
| 182 | - ) |
|
| 183 | - ], |
|
| 184 | - [ |
|
| 185 | - 'ecrire_meta', |
|
| 186 | - 'gerer_trad_objets', |
|
| 187 | - implode( |
|
| 188 | - ',', |
|
| 189 | - array_diff( |
|
| 190 | - [ |
|
| 191 | - (isset($GLOBALS['meta']['gerer_trad']) and $GLOBALS['meta']['gerer_trad'] == 'oui') |
|
| 192 | - ? 'spip_articles' : '' |
|
| 193 | - ], |
|
| 194 | - [''] |
|
| 195 | - ) |
|
| 196 | - ) |
|
| 197 | - ], |
|
| 168 | + [ |
|
| 169 | + 'ecrire_meta', |
|
| 170 | + 'multi_objets', |
|
| 171 | + implode( |
|
| 172 | + ',', |
|
| 173 | + array_diff( |
|
| 174 | + [ |
|
| 175 | + (isset($GLOBALS['meta']['multi_rubriques']) and $GLOBALS['meta']['multi_rubriques'] == 'oui') |
|
| 176 | + ? 'spip_rubriques' : '', |
|
| 177 | + (isset($GLOBALS['meta']['multi_articles']) and $GLOBALS['meta']['multi_articles'] == 'oui') |
|
| 178 | + ? 'spip_articles' : '' |
|
| 179 | + ], |
|
| 180 | + [''] |
|
| 181 | + ) |
|
| 182 | + ) |
|
| 183 | + ], |
|
| 184 | + [ |
|
| 185 | + 'ecrire_meta', |
|
| 186 | + 'gerer_trad_objets', |
|
| 187 | + implode( |
|
| 188 | + ',', |
|
| 189 | + array_diff( |
|
| 190 | + [ |
|
| 191 | + (isset($GLOBALS['meta']['gerer_trad']) and $GLOBALS['meta']['gerer_trad'] == 'oui') |
|
| 192 | + ? 'spip_articles' : '' |
|
| 193 | + ], |
|
| 194 | + [''] |
|
| 195 | + ) |
|
| 196 | + ) |
|
| 197 | + ], |
|
| 198 | 198 | ]; |
| 199 | 199 | $GLOBALS['maj'][17555] = [ |
| 200 | - ['sql_alter', "TABLE spip_resultats ADD table_objet varchar(30) DEFAULT '' NOT NULL"], |
|
| 201 | - ['sql_alter', "TABLE spip_resultats ADD serveur char(16) DEFAULT '' NOT NULL"], |
|
| 200 | + ['sql_alter', "TABLE spip_resultats ADD table_objet varchar(30) DEFAULT '' NOT NULL"], |
|
| 201 | + ['sql_alter', "TABLE spip_resultats ADD serveur char(16) DEFAULT '' NOT NULL"], |
|
| 202 | 202 | ]; |
| 203 | 203 | |
| 204 | 204 | $GLOBALS['maj'][17563] = [ |
| 205 | - ['sql_alter', "TABLE spip_articles ADD virtuel VARCHAR(255) DEFAULT '' NOT NULL"], |
|
| 206 | - ['sql_update', 'spip_articles', ['virtuel' => 'SUBSTRING(chapo,2)', 'chapo' => "''"], "chapo LIKE '=_%'"], |
|
| 205 | + ['sql_alter', "TABLE spip_articles ADD virtuel VARCHAR(255) DEFAULT '' NOT NULL"], |
|
| 206 | + ['sql_update', 'spip_articles', ['virtuel' => 'SUBSTRING(chapo,2)', 'chapo' => "''"], "chapo LIKE '=_%'"], |
|
| 207 | 207 | ]; |
| 208 | 208 | |
| 209 | 209 | $GLOBALS['maj'][17577] = [ |
| 210 | - ['maj_tables', ['spip_jobs', 'spip_jobs_liens']], |
|
| 210 | + ['maj_tables', ['spip_jobs', 'spip_jobs_liens']], |
|
| 211 | 211 | ]; |
| 212 | 212 | |
| 213 | 213 | $GLOBALS['maj'][17743] = [ |
| 214 | - ['sql_update', 'spip_auteurs', ['prefs' => 'bio', 'bio' => "''"], "statut='nouveau' AND bio<>''"], |
|
| 214 | + ['sql_update', 'spip_auteurs', ['prefs' => 'bio', 'bio' => "''"], "statut='nouveau' AND bio<>''"], |
|
| 215 | 215 | ]; |
| 216 | 216 | |
| 217 | 217 | $GLOBALS['maj'][18219] = [ |
| 218 | - ['sql_alter', 'TABLE spip_rubriques DROP id_import'], |
|
| 219 | - ['sql_alter', 'TABLE spip_rubriques DROP export'], |
|
| 218 | + ['sql_alter', 'TABLE spip_rubriques DROP id_import'], |
|
| 219 | + ['sql_alter', 'TABLE spip_rubriques DROP export'], |
|
| 220 | 220 | ]; |
| 221 | 221 | |
| 222 | 222 | $GLOBALS['maj'][18310] = [ |
| 223 | - ['sql_alter', "TABLE spip_auteurs_liens CHANGE vu vu VARCHAR(6) DEFAULT 'non' NOT NULL"], |
|
| 223 | + ['sql_alter', "TABLE spip_auteurs_liens CHANGE vu vu VARCHAR(6) DEFAULT 'non' NOT NULL"], |
|
| 224 | 224 | ]; |
| 225 | 225 | |
| 226 | 226 | $GLOBALS['maj'][18597] = [ |
| 227 | - ['sql_alter', "TABLE spip_rubriques ADD profondeur smallint(5) DEFAULT '0' NOT NULL"], |
|
| 228 | - ['maj_propager_les_secteurs'], |
|
| 227 | + ['sql_alter', "TABLE spip_rubriques ADD profondeur smallint(5) DEFAULT '0' NOT NULL"], |
|
| 228 | + ['maj_propager_les_secteurs'], |
|
| 229 | 229 | ]; |
| 230 | 230 | |
| 231 | 231 | $GLOBALS['maj'][18955] = [ |
| 232 | - ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX id_objet (id_objet)'], |
|
| 233 | - ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX objet (objet)'], |
|
| 232 | + ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX id_objet (id_objet)'], |
|
| 233 | + ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX objet (objet)'], |
|
| 234 | 234 | ]; |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | * @uses propager_les_secteurs() |
| 240 | 240 | **/ |
| 241 | 241 | function maj_propager_les_secteurs() { |
| 242 | - include_spip('inc/rubriques'); |
|
| 243 | - propager_les_secteurs(); |
|
| 242 | + include_spip('inc/rubriques'); |
|
| 243 | + propager_les_secteurs(); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -253,87 +253,87 @@ discard block |
||
| 253 | 253 | function maj_collation_sqlite() { |
| 254 | 254 | |
| 255 | 255 | |
| 256 | - include_spip('base/dump'); |
|
| 257 | - $tables = base_lister_toutes_tables(); |
|
| 258 | - |
|
| 259 | - // rien a faire si base non sqlite |
|
| 260 | - if (strncmp($GLOBALS['connexions'][0]['type'], 'sqlite', 6) !== 0) { |
|
| 261 | - return; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 265 | - // forcer le vidage de cache |
|
| 266 | - $trouver_table(''); |
|
| 267 | - |
|
| 268 | - // cas particulier spip_auteurs : retablir le collate binary sur le login |
|
| 269 | - $desc = $trouver_table('spip_auteurs'); |
|
| 270 | - spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 271 | - if (stripos($desc['field']['login'], 'BINARY') === false) { |
|
| 272 | - spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
|
| 273 | - sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
|
| 274 | - $trouver_table(''); |
|
| 275 | - $new_desc = $trouver_table('spip_auteurs'); |
|
| 276 | - spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - foreach ($tables as $table) { |
|
| 280 | - if (time() >= _TIME_OUT) { |
|
| 281 | - return; |
|
| 282 | - } |
|
| 283 | - if ($desc = $trouver_table($table)) { |
|
| 284 | - $desc_collate = _sqlite_remplacements_definitions_table($desc['field']); |
|
| 285 | - if ($d = array_diff($desc['field'], $desc_collate)) { |
|
| 286 | - spip_log("Table $table COLLATE incorrects", 'maj'); |
|
| 287 | - |
|
| 288 | - // cas particulier spip_urls : |
|
| 289 | - // supprimer les doublons avant conversion sinon echec (on garde les urls les plus recentes) |
|
| 290 | - if ($table == 'spip_urls') { |
|
| 291 | - // par date DESC pour conserver les urls les plus recentes |
|
| 292 | - $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
|
| 293 | - $urls = []; |
|
| 294 | - foreach ($data as $d) { |
|
| 295 | - $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 296 | - if (!isset($urls[$key])) { |
|
| 297 | - $urls[$key] = true; |
|
| 298 | - } else { |
|
| 299 | - spip_log( |
|
| 300 | - 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 302 | - ); |
|
| 303 | - sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - foreach ($desc['field'] as $field => $type) { |
|
| 308 | - if ($desc['field'][$field] !== $desc_collate[$field]) { |
|
| 309 | - spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | - sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 311 | - $trouver_table(''); |
|
| 312 | - $new_desc = $trouver_table($table); |
|
| 313 | - spip_log( |
|
| 314 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 316 | - ); |
|
| 317 | - continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - // forcer le vidage de cache |
|
| 325 | - $trouver_table(''); |
|
| 256 | + include_spip('base/dump'); |
|
| 257 | + $tables = base_lister_toutes_tables(); |
|
| 258 | + |
|
| 259 | + // rien a faire si base non sqlite |
|
| 260 | + if (strncmp($GLOBALS['connexions'][0]['type'], 'sqlite', 6) !== 0) { |
|
| 261 | + return; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 265 | + // forcer le vidage de cache |
|
| 266 | + $trouver_table(''); |
|
| 267 | + |
|
| 268 | + // cas particulier spip_auteurs : retablir le collate binary sur le login |
|
| 269 | + $desc = $trouver_table('spip_auteurs'); |
|
| 270 | + spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 271 | + if (stripos($desc['field']['login'], 'BINARY') === false) { |
|
| 272 | + spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
|
| 273 | + sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
|
| 274 | + $trouver_table(''); |
|
| 275 | + $new_desc = $trouver_table('spip_auteurs'); |
|
| 276 | + spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + foreach ($tables as $table) { |
|
| 280 | + if (time() >= _TIME_OUT) { |
|
| 281 | + return; |
|
| 282 | + } |
|
| 283 | + if ($desc = $trouver_table($table)) { |
|
| 284 | + $desc_collate = _sqlite_remplacements_definitions_table($desc['field']); |
|
| 285 | + if ($d = array_diff($desc['field'], $desc_collate)) { |
|
| 286 | + spip_log("Table $table COLLATE incorrects", 'maj'); |
|
| 287 | + |
|
| 288 | + // cas particulier spip_urls : |
|
| 289 | + // supprimer les doublons avant conversion sinon echec (on garde les urls les plus recentes) |
|
| 290 | + if ($table == 'spip_urls') { |
|
| 291 | + // par date DESC pour conserver les urls les plus recentes |
|
| 292 | + $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
|
| 293 | + $urls = []; |
|
| 294 | + foreach ($data as $d) { |
|
| 295 | + $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 296 | + if (!isset($urls[$key])) { |
|
| 297 | + $urls[$key] = true; |
|
| 298 | + } else { |
|
| 299 | + spip_log( |
|
| 300 | + 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 302 | + ); |
|
| 303 | + sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + foreach ($desc['field'] as $field => $type) { |
|
| 308 | + if ($desc['field'][$field] !== $desc_collate[$field]) { |
|
| 309 | + spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | + sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 311 | + $trouver_table(''); |
|
| 312 | + $new_desc = $trouver_table($table); |
|
| 313 | + spip_log( |
|
| 314 | + "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 316 | + ); |
|
| 317 | + continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + // forcer le vidage de cache |
|
| 325 | + $trouver_table(''); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | |
| 329 | 329 | $GLOBALS['maj'][19236] = [ |
| 330 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
|
| 331 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | - ['maj_collation_sqlite'], |
|
| 330 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
|
| 331 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | + ['maj_collation_sqlite'], |
|
| 333 | 333 | ]; |
| 334 | 334 | |
| 335 | 335 | $GLOBALS['maj'][19268] = [ |
| 336 | - ['supprimer_toutes_sessions'], |
|
| 336 | + ['supprimer_toutes_sessions'], |
|
| 337 | 337 | ]; |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -342,13 +342,13 @@ discard block |
||
| 342 | 342 | * Obligera tous les auteurs à se reconnecter ! |
| 343 | 343 | **/ |
| 344 | 344 | function supprimer_toutes_sessions() { |
| 345 | - spip_log('supprimer sessions auteur'); |
|
| 346 | - if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 347 | - while (($f = readdir($dir)) !== false) { |
|
| 348 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 349 | - if (time() >= _TIME_OUT) { |
|
| 350 | - return; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - } |
|
| 345 | + spip_log('supprimer sessions auteur'); |
|
| 346 | + if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 347 | + while (($f = readdir($dir)) !== false) { |
|
| 348 | + spip_unlink(_DIR_SESSIONS . $f); |
|
| 349 | + if (time() >= _TIME_OUT) { |
|
| 350 | + return; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | 354 | } |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
| 61 | 61 | |
| 62 | 62 | $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
| 63 | - $pivots = (isset($exceptions_pluriel[$pivot]) ? $exceptions_pluriel[$pivot] : $pivot . 's'); |
|
| 64 | - $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | - $id_pivot = 'id_' . $pivot; |
|
| 63 | + $pivots = (isset($exceptions_pluriel[$pivot]) ? $exceptions_pluriel[$pivot] : $pivot.'s'); |
|
| 64 | + $liens = 'spip_'.$pivots.'_liens'; |
|
| 65 | + $id_pivot = 'id_'.$pivot; |
|
| 66 | 66 | // Creer spip_auteurs_liens |
| 67 | 67 | global $tables_auxiliaires; |
| 68 | 68 | if (!$l) { |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | $l = preg_replace(',[^\w],', '', $l); // securite |
| 75 | 75 | $primary = "id_$l"; |
| 76 | 76 | $objet = ($l == 'syndic' ? 'site' : $l); |
| 77 | - $ls = (isset($exceptions_pluriel[$l]) ? $exceptions_pluriel[$l] : $l . 's'); |
|
| 78 | - $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 77 | + $ls = (isset($exceptions_pluriel[$l]) ? $exceptions_pluriel[$l] : $l.'s'); |
|
| 78 | + $ancienne_table = 'spip_'.$pivots.'_'.$ls; |
|
| 79 | 79 | $pool = 400; |
| 80 | 80 | |
| 81 | 81 | $trouver_table = charger_fonction('trouver_table', 'base'); |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
| 112 | 112 | $insert = []; |
| 113 | 113 | foreach ($ids as $id) { |
| 114 | - $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | - while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 114 | + $n = sql_countsel($liens, "objet='$objet' AND id_objet=".intval($id)); |
|
| 115 | + while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=".intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | 116 | $n += count($t); |
| 117 | 117 | // empiler en s'assurant a minima de l'unicite |
| 118 | 118 | while ($r = array_shift($t)) { |
| 119 | - $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 119 | + $insert[$r[$id_pivot].':'.$r['id_objet']] = $r; |
|
| 120 | 120 | } |
| 121 | 121 | if (count($insert) >= $sub_pool) { |
| 122 | 122 | maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | // cas particulier spip_auteurs : retablir le collate binary sur le login |
| 269 | 269 | $desc = $trouver_table('spip_auteurs'); |
| 270 | - spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 270 | + spip_log('spip_auteurs : '.var_export($desc['field'], true), 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 271 | 271 | if (stripos($desc['field']['login'], 'BINARY') === false) { |
| 272 | 272 | spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
| 273 | 273 | sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
| 274 | 274 | $trouver_table(''); |
| 275 | 275 | $new_desc = $trouver_table('spip_auteurs'); |
| 276 | - spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 276 | + spip_log('Apres conversion spip_auteurs : '.var_export($new_desc['field'], true), 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | foreach ($tables as $table) { |
@@ -292,27 +292,27 @@ discard block |
||
| 292 | 292 | $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
| 293 | 293 | $urls = []; |
| 294 | 294 | foreach ($data as $d) { |
| 295 | - $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 295 | + $key = $d['id_parent'].'::'.strtolower($d['url']); |
|
| 296 | 296 | if (!isset($urls[$key])) { |
| 297 | 297 | $urls[$key] = true; |
| 298 | 298 | } else { |
| 299 | 299 | spip_log( |
| 300 | - 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 300 | + 'Suppression doublon dans spip_urls avant conversion : '.serialize($d), |
|
| 301 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 302 | 302 | ); |
| 303 | - sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 303 | + sql_delete('spip_urls', 'id_parent='.sql_quote($d['id_parent']).' AND url='.sql_quote($d['url'])); |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | foreach ($desc['field'] as $field => $type) { |
| 308 | 308 | if ($desc['field'][$field] !== $desc_collate[$field]) { |
| 309 | - spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | - sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 309 | + spip_log("Conversion COLLATE table $table", 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 310 | + sql_alter("table $table change $field $field ".$desc_collate[$field]); |
|
| 311 | 311 | $trouver_table(''); |
| 312 | 312 | $new_desc = $trouver_table($table); |
| 313 | 313 | spip_log( |
| 314 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 314 | + "Apres conversion $table : ".var_export($new_desc['field'], true), |
|
| 315 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 316 | 316 | ); |
| 317 | 317 | continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
| 318 | 318 | } |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | |
| 329 | 329 | $GLOBALS['maj'][19236] = [ |
| 330 | 330 | ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
| 331 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 331 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | 332 | ['maj_collation_sqlite'], |
| 333 | 333 | ]; |
| 334 | 334 | |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | spip_log('supprimer sessions auteur'); |
| 346 | 346 | if ($dir = opendir(_DIR_SESSIONS)) { |
| 347 | 347 | while (($f = readdir($dir)) !== false) { |
| 348 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 348 | + spip_unlink(_DIR_SESSIONS.$f); |
|
| 349 | 349 | if (time() >= _TIME_OUT) { |
| 350 | 350 | return; |
| 351 | 351 | } |