[SPIP] ~v3.0.20-->v3.0.25
[lhc/web/clavette_www.git] / www / ecrire / public / styliser.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
12
13
14 if (!defined('_ECRIRE_INC_VERSION')) return;
15
16 // Ce fichier doit imperativement definir la fonction ci-dessous:
17
18 /**
19 * Determiner le squelette qui sera utilise pour rendre la page ou le bloc
20 * a partir de $fond et du $contetxe
21 *
22 * Actuellement tous les squelettes se terminent par .html
23 * pour des raisons historiques, ce qui est trompeur
24 *
25 * @param string $fond
26 * @param array $contexte
27 * @param string $lang
28 * @param string $connect
29 * @param string $ext
30 * @return array
31 *
32 * http://doc.spip.org/@public_styliser_dist
33 */
34 function public_styliser_dist($fond, $contexte, $lang='', $connect='') {
35 static $styliser_par_z;
36
37 // s'assurer que le fond est licite
38 // car il peut etre construit a partir d'une variable d'environnement
39 if (strpos($fond,"../")!==false OR strncmp($fond,'/',1)==0)
40 $fond = "404";
41
42 // Choisir entre $fond-dist.html, $fond=7.html, etc?
43 $id_rubrique = 0;
44 // Chercher le fond qui va servir de squelette
45 if ($r = quete_rubrique_fond($contexte))
46 list($id_rubrique, $lang) = $r;
47
48 // trouver un squelette du nom demande
49 // ne rien dire si on ne trouve pas,
50 // c'est l'appelant qui sait comment gerer la situation
51 // ou les plugins qui feront mieux dans le pipeline
52 $squelette = trouver_fond($fond,"",true);
53 $ext = $squelette['extension'];
54
55 $flux = array(
56 'args' => array(
57 'id_rubrique' => $id_rubrique,
58 'ext' => $ext,
59 'fond' => $fond,
60 'lang' => $lang,
61 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme
62 'connect' => $connect
63 ),
64 'data' => $squelette['fond'],
65 );
66
67 if (test_espace_prive() OR defined('_ZPIP')) {
68 if (!$styliser_par_z)
69 $styliser_par_z = charger_fonction('styliser_par_z','public');
70 $flux = $styliser_par_z($flux);
71 }
72
73 $flux = styliser_par_objets($flux);
74
75 // pipeline styliser
76 $squelette = pipeline('styliser', $flux);
77
78 return array($squelette, $ext, $ext, "$squelette.$ext");
79 }
80
81 function styliser_par_objets($flux){
82 if (test_espace_prive()
83 AND !$squelette = $flux['data']
84 AND strncmp($flux['args']['fond'],'prive/objets/',13)==0
85 AND $echafauder = charger_fonction('echafauder','prive',true)) {
86 if (strncmp($flux['args']['fond'],'prive/objets/liste/',19)==0){
87 $table = table_objet(substr($flux['args']['fond'],19));
88 $table_sql = table_objet_sql($table);
89 $objets = lister_tables_objets_sql();
90 if (isset($objets[$table_sql]))
91 $flux['data'] = $echafauder($table,$table,$table_sql,"prive/objets/liste/objets",$flux['args']['ext']);
92 }
93 if (strncmp($flux['args']['fond'],'prive/objets/contenu/',21)==0){
94 $type = substr($flux['args']['fond'],21);
95 $table = table_objet($type);
96 $table_sql = table_objet_sql($table);
97 $objets = lister_tables_objets_sql();
98 if (isset($objets[$table_sql]))
99 $flux['data'] = $echafauder($type,$table,$table_sql,"prive/objets/contenu/objet",$flux['args']['ext']);
100 }
101 }
102 return $flux;
103 }
104
105 /**
106 * Calcul de la rubrique associee a la requete
107 * (selection de squelette specifique par id_rubrique & lang)
108 *
109 * attention, on repete cela a chaque inclusion,
110 * on optimise donc pour ne faire la recherche qu'une fois
111 * par contexte semblable du point de vue des id_xx
112 *
113 * http://doc.spip.org/@quete_rubrique_fond
114 *
115 * @staticvar array $liste_objets
116 * @param array $contexte
117 * @return array
118 */
119 function quete_rubrique_fond($contexte) {
120 static $liste_objets = null;
121 static $quete = array();
122 if (is_null($liste_objets)) {
123 $liste_objets = array();
124 include_spip('inc/urls');
125 include_spip('public/quete');
126 $l = urls_liste_objets(false);
127 // placer la rubrique en tete des objets
128 $l = array_diff($l,array('rubrique'));
129 array_unshift($l, 'rubrique');
130 foreach($l as $objet){
131 $id = id_table_objet($objet);
132 if (!isset($liste_objets[$id]))
133 $liste_objets[$id] = objet_type($objet,false);
134 }
135 }
136 $c = array_intersect_key($contexte,$liste_objets);
137 if (!count($c)) return false;
138
139 $c = array_map('intval',$c);
140 $s = serialize($c);
141 if (isset($quete[$s]))
142 return $quete[$s];
143
144 if (isset($c['id_rubrique']) AND $r = $c['id_rubrique']){
145 unset($c['id_rubrique']);
146 $c = array('id_rubrique'=>$r) + $c;
147 }
148
149 foreach($c as $_id=>$id) {
150 if ($id
151 AND $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]),$id)) {
152 $lang = isset($row['lang']) ? $row['lang'] : '';
153 if ($_id=='id_rubrique' OR (isset($row['id_rubrique']) AND $id=$row['id_rubrique']))
154 return $quete[$s] = array ($id, $lang);
155 }
156 }
157 return $quete[$s] = false;
158 }
159 ?>