1 | <?php |
---|
2 | # ACS |
---|
3 | # (Plugin Spip) |
---|
4 | # http://acs.geomaticien.org |
---|
5 | # |
---|
6 | # Copyright Daniel FAIVRE, 2007-2011 |
---|
7 | # Copyleft: licence GPL - Cf. LICENCES.txt |
---|
8 | |
---|
9 | include_spip('inc/composant/composants_variables'); |
---|
10 | include_spip('inc/composant/pages_liste'); |
---|
11 | |
---|
12 | /** |
---|
13 | * Analyse une page |
---|
14 | * Retourne un tableau des variables ACS, des balises et des inclusions |
---|
15 | */ |
---|
16 | function analyse_page($page, $mode_source) { |
---|
17 | $modeles = pages_liste(); |
---|
18 | $modeles = $modeles['modeles']; |
---|
19 | if (is_array($modeles) && (count($modeles) > 0)) { |
---|
20 | foreach ($modeles as $m=>$src) { |
---|
21 | $modeles_regexp .= '#'.strtoupper($m).'|'; |
---|
22 | } |
---|
23 | $modeles_regexp = substr($modeles_regexp, 0, -1); |
---|
24 | } |
---|
25 | |
---|
26 | $balises = explode(', ', liste_balises()); |
---|
27 | usort($balises, "compare_taille"); |
---|
28 | $balises = '#'.implode('|#', $balises); |
---|
29 | |
---|
30 | // Quelques définitions de regexp : |
---|
31 | // capture tout entre accolades jusqu'à trois niveaux d'imbrication |
---|
32 | $reg_entre_accolades = '(?:\{(?:(?:[^\}]*\{(?:[^\}]*\{[^\}]*\})[\s]*\})*[\s]*|(?:[^\}]*\{[^\}]*\})*[\s]*|[^}]*)*\})'; |
---|
33 | // filtre spip |
---|
34 | $reg_filtre_spip = '(?:\|(?:==|!=|\?)*[\w]*(?:'.$reg_entre_accolades.')*)'; |
---|
35 | |
---|
36 | // Les types de tags spip repérés en mode schéma |
---|
37 | $reg[] = array('REM', 2, '(\[\(#REM\)([^\]]*)\])'); |
---|
38 | if ($modeles_regexp) |
---|
39 | $reg[] = array('MODELE', 3, '(('.$modeles_regexp.')('.$reg_entre_accolades.'|'.$reg_filtre_spip.')*)'); |
---|
40 | $reg[] = array('INCLURE', 3, '((?:<|#)INCLU[R|D]E[\s]*\{fond=([^\}]*)\}((?:[\s]*'.$reg_entre_accolades.')*)>?)'); |
---|
41 | $reg[] = array('BOUCLE', 4, '(<BOUCLE[_]?([^(]*)\(([^)]*)\)((?:>=|[^\>])*)>)'); |
---|
42 | $reg[] = array('FIN_BOUCLE', 2, '(<\/BOUCLE[_]?([^>]*)>)'); |
---|
43 | if ($mode_source) { |
---|
44 | $reg[] = array('B', 1, '(<B_[^>]*>)'); |
---|
45 | $reg[] = array('FIN_B', 1, '(<\/B_[^>]*>)'); |
---|
46 | $reg[] = array('TRAD', 1, '(<:[\w]*:>)'); |
---|
47 | } |
---|
48 | $reg[] = array('BALISE', 3, '(('.$balises.')('.$reg_entre_accolades.'|'.$reg_filtre_spip.')*)'); |
---|
49 | |
---|
50 | $def = array(); |
---|
51 | foreach ($reg as $rx) { |
---|
52 | $def[] = array('spip_tag' => $rx[0], 'nb' => $rx[1]); |
---|
53 | $regexp .= $rx[2].'|'; |
---|
54 | } |
---|
55 | |
---|
56 | // La structure $analyse détermine l'analyse recursive avec regexp |
---|
57 | $analyse = array( |
---|
58 | 'regexp' => '/'.substr($regexp, 0, -1).'/s', |
---|
59 | 'regdef' => $def, |
---|
60 | 'mode_source' => $mode_source |
---|
61 | ); |
---|
62 | return page_includes($page, $analyse); |
---|
63 | } |
---|
64 | |
---|
65 | // Analyse séquentiellement la page, et retourne un tableau constitué |
---|
66 | // d'un tableau des variables ACS trouveés |
---|
67 | // et d'un tableau des contenus avec leurs positions.de début et de fin |
---|
68 | // (fonction récursive) |
---|
69 | function page_includes( |
---|
70 | $texte, // Texte à analyser |
---|
71 | &$analyse, // Structure d'analyse |
---|
72 | &$includes=array( |
---|
73 | 'tags' => array(), |
---|
74 | 'vars' => array() |
---|
75 | ), // tableau des tages et des variables trouvés |
---|
76 | $offset=0, // offset depuis le début de $pg |
---|
77 | $tagoffset=0 // offset depuis le début du tag |
---|
78 | ) { |
---|
79 | static $k; |
---|
80 | if ($k > 9999) return $includes; |
---|
81 | $k++; |
---|
82 | |
---|
83 | if (preg_match($analyse['regexp'], $texte, $matches, PREG_OFFSET_CAPTURE, $offset)) { |
---|
84 | //print_r($matches); |
---|
85 | $indice = 1; |
---|
86 | foreach($analyse['regdef'] as $capture) { |
---|
87 | if ($matches[$indice][0]) { |
---|
88 | $args = array(); |
---|
89 | $contenu = ''; |
---|
90 | //echo "<br>".$capture['f']."<br>"; |
---|
91 | $matched = $matches[$indice][0]; |
---|
92 | $debut = $matches[$indice][1]; |
---|
93 | $fin = $debut + strlen($matched); |
---|
94 | for ($i = $indice; $i < $indice + $capture['nb']; $i++) { |
---|
95 | //echo " [".($i)."][0]=".htmlspecialchars($matches[$i][0])."<br>"; |
---|
96 | $args[] = $matches[$i][0]; |
---|
97 | } |
---|
98 | if (is_callable('pi_'.$capture['spip_tag'])) { |
---|
99 | $contenu = call_user_func('pi_'.$capture['spip_tag'], array($args, &$analyse, &$includes)); |
---|
100 | if (is_array($contenu)) { |
---|
101 | if ($contenu[1]) |
---|
102 | $includes['vars'][] = $contenu[1]; |
---|
103 | $contenu = $contenu[0]; |
---|
104 | } |
---|
105 | } |
---|
106 | if ($contenu) |
---|
107 | $includes['tags'][$tagoffset + $debut] = array( |
---|
108 | 'fin' => $tagoffset + $fin, |
---|
109 | 'contenu' => $contenu, |
---|
110 | 'type' => $capture['spip_tag'] |
---|
111 | ); |
---|
112 | page_includes($matched, $analyse, $includes, 1, $tagoffset + $debut); // Recherche des imbrications |
---|
113 | } |
---|
114 | $indice = $indice + $capture['nb']; |
---|
115 | } |
---|
116 | page_includes($texte, $analyse, $includes, $fin, $tagoffset); // Va au tag suivant |
---|
117 | } |
---|
118 | return $includes; |
---|
119 | } |
---|
120 | |
---|
121 | function pi_REM($args) { |
---|
122 | if ($args[1]['mode_source']) return $args[0][0]; |
---|
123 | |
---|
124 | return '<div class="spip_params onlinehelp pliable">'.nl2br($args[0][1]).'</div>'; |
---|
125 | } |
---|
126 | |
---|
127 | function pi_MODELE($args) { |
---|
128 | if ($args[1]['mode_source']) return $args[0][0]; |
---|
129 | |
---|
130 | $m = $args[0][1]; |
---|
131 | $p = $args[0][2]; |
---|
132 | |
---|
133 | $r = indent($args[1]['indentation']).'<span class="col_MODELE" title="'._T('acs:modele').' '.strtolower(substr($m, 1)).($p ? ' '.htmlspecialchars($p) : '').'" style="color:#4f00af">'.$m; |
---|
134 | if ($p) |
---|
135 | $r .= ' <span class="spip_params pliable">'.indent($args[1]['indentation']).str_replace('}{', '} {', htmlspecialchars($p)).'</span>'; |
---|
136 | $r .= '</span>'; |
---|
137 | return $r; |
---|
138 | } |
---|
139 | |
---|
140 | function pi_INCLURE($args) { |
---|
141 | if ($args[1]['mode_source']) return $args[0][0]; |
---|
142 | |
---|
143 | $include = $args[0][1]; |
---|
144 | $param = $args[0][2]; |
---|
145 | |
---|
146 | if (preg_match('/{nic=(\d*)\}/', $args[0][0], $matches)) { |
---|
147 | $nic = $matches[1]; |
---|
148 | } |
---|
149 | // Inclusion d'un composant |
---|
150 | if (substr($include, 0, 11) == 'composants/') { |
---|
151 | $r = affiche_widgy($include, $param, $args[1]['indentation'], $nic); |
---|
152 | } |
---|
153 | else { |
---|
154 | // inclusion classique |
---|
155 | if (find_in_path($include.'.html')) |
---|
156 | $r = indent($args[1]['indentation']).'<a class="'.get_widget_class($include, $param['on'], 'widgy').' lien_page" style="background: none" href="?exec=acs&onglet=page&pg='.$include.'" onclick=\'$("#page_infos").empty(); |
---|
157 | AjaxSqueeze("?exec=acs_page_get_infos&pg=" + this.text, "page_infos"); |
---|
158 | return false;\' title="'.$param.'">'.$include.'</a>'; |
---|
159 | else |
---|
160 | $r = indent($args[1]['indentation']).'<a class="'.get_widget_class($include, $param['on'], 'widgy').' lien_page" style="background: #efefef; border-style: solid; color: red; text-decoration: blink; " title="'._T('acs:err_fichier_absent', array('file' => $include)).'">'.$include.'</a>'; |
---|
161 | } |
---|
162 | $r = $r; |
---|
163 | if ($param) |
---|
164 | $r .= '<div class="spip_params pliable">'.indent($args[1]['indentation']).str_replace('}{', '} {', $param).'</div>'; |
---|
165 | return $r; |
---|
166 | } |
---|
167 | |
---|
168 | function pi_BOUCLE($args) { |
---|
169 | if ($args[1]['mode_source']) return $args[0][0]; |
---|
170 | |
---|
171 | $boucle = $args[0][1]; |
---|
172 | $type = $args[0][2]; |
---|
173 | $param = $args[0][3]; |
---|
174 | |
---|
175 | $r = '<div class="col_BOUCLE" title="'._T('acs:boucle').' '.strtolower($type).' '.$param.'">'.indent($args[1]['indentation']).$boucle.' ('.$type.')'; |
---|
176 | if ($param) |
---|
177 | $r .= indent($args[1]['indentation']).' <span class="spip_params pliable">'.indent($args[1]['indentation']).str_replace('}{', '} {', $param).'</span>'; |
---|
178 | $r .= '</div>'; |
---|
179 | $args[1]['indentation']++; |
---|
180 | return $r; |
---|
181 | } |
---|
182 | |
---|
183 | function pi_FIN_BOUCLE($args) { |
---|
184 | if ($args[1]['mode_source']) return $args[0][0]; |
---|
185 | $args[1]['indentation']--; |
---|
186 | return '<div class="col_FIN_BOUCLE">'.indent($args[1]['indentation']).'/'.$args[0][1].'</div>'; |
---|
187 | } |
---|
188 | |
---|
189 | function pi_BALISE($args) { |
---|
190 | $balise = substr($args[0][1], 1); |
---|
191 | // on a trouve une variable ACS presumee |
---|
192 | if ($balise == 'VAR') { |
---|
193 | // On lit le contenu entre accolades apres #VAR |
---|
194 | if (preg_match('/{acs(\w*)\}/', $args[0][2], $matches)) { |
---|
195 | $var = $matches[1]; |
---|
196 | // on verifie que c'est bien une variable ACS : |
---|
197 | $lv = liste_variables(); |
---|
198 | if (in_array($var, array_keys($lv))) { |
---|
199 | $c = $lv[$var]['c']; |
---|
200 | $html = '<a class="col_VAR" href="?exec=acs&onglet=composants&composant='.$c.($lv['c']['nic'] ? '&nic='.$lv['c']['nic']: '').'" title="'._T('acs:composant').' '.ucfirst(str_replace('_', ' ', $c)).'">acs'.$var.'</a>'; |
---|
201 | } |
---|
202 | } |
---|
203 | } |
---|
204 | return array(($args[1]['mode_source'] ? $args[0][0] : false), $html); |
---|
205 | } |
---|
206 | |
---|
207 | function affiche_widgy($include, $param, $indentation, $nic) { |
---|
208 | $include = substr($include, 11); |
---|
209 | if ($pos = strpos($include, '/')) { |
---|
210 | if (substr($include, 0, $pos) == substr($include, $pos + 1)) { |
---|
211 | $label = substr($include, 0, $pos); |
---|
212 | } |
---|
213 | else { |
---|
214 | $label = $include; |
---|
215 | } |
---|
216 | $composant = substr($include, 0, $pos); |
---|
217 | } |
---|
218 | return widgy($composant, $param, $label, $indentation, $nic); |
---|
219 | } |
---|
220 | |
---|
221 | function widgy($composant, $param, $label='', $indentation=0, $nic = '', $recursive_indent = 0, $in_horizontal = false) { |
---|
222 | $label = ucfirst(str_replace('_', ' ', $label)); |
---|
223 | |
---|
224 | $horizontal = ($GLOBALS['meta']['acs'.ucfirst($composant).$nic.'Orientation'] == "horizontal") ? true : false; |
---|
225 | $content .= $horizontal ? '<tr>' : ''; |
---|
226 | |
---|
227 | // On recherche ce que contient le widgy, recursivement |
---|
228 | $cv = composants_variables(); |
---|
229 | |
---|
230 | if (is_array($cv) && is_array($cv[$composant]) && is_array($cv[$composant]['vars'])) { |
---|
231 | foreach($cv[$composant]['vars'] as $varname=>$v) { |
---|
232 | if ($v['type'] != 'widget') |
---|
233 | continue; |
---|
234 | $var = 'acs'.ucfirst($composant).$nic.ucfirst($varname); |
---|
235 | if (isset($GLOBALS['meta'][$var]) && $GLOBALS['meta'][$var]) { |
---|
236 | $ci = explode('-', $GLOBALS['meta'][$var]); |
---|
237 | $cinom = $ci[0]; |
---|
238 | $cinic = $ci[1]; |
---|
239 | $cilabel = $cinom; |
---|
240 | $content .= (!$horizontal ? '<tr>' : ''); |
---|
241 | $content .= '<td class="widgy_included_label"><a class="nompage" href="?exec=acs&onglet=composants&composant='.$composant.($nic ? '&nic='.$nic : '').'" title="acs'.$varname.'">'.substr($varname, strlen($composant.$nic)).'</a>'.widgy($cinom, '', $cilabel, $indentation, $cinic, 1, $horizontal).'</td>'; |
---|
242 | $content .= (!$horizontal ? '</tr>' : ''); |
---|
243 | } |
---|
244 | } |
---|
245 | } |
---|
246 | $content .= $horizontal ? '</tr>' : ''; |
---|
247 | |
---|
248 | // On recupere le Nom du composant |
---|
249 | $cvn = 'acs'.ucfirst($composant).$nic.'Nom'; |
---|
250 | if (isset($GLOBALS['meta'][$cvn])) { |
---|
251 | $lbl = $GLOBALS['meta'][$cvn]; |
---|
252 | $title = $label.($nic ? ' '.$nic : ''). ' ('.$lbl.')'; |
---|
253 | $lbl = str_replace(' ', ' ', couper($lbl, 18)); |
---|
254 | } |
---|
255 | else { |
---|
256 | $lbl = $label.($nic ? ' '.$nic : ''); |
---|
257 | $title = _T('acs:composant').' '.$label.' '.$nic; |
---|
258 | } |
---|
259 | $titleHTML = ' title="'.$title.'"'; |
---|
260 | // affichage du contenu du widgy avec l'indentation voulue |
---|
261 | $indentationHTML = $in_horizontal ? '' : '<td>'.indent($indentation + $recursive_indent).'</td>'; |
---|
262 | $over = $cv[$composant]['over']; |
---|
263 | $on = ($GLOBALS['meta']['acs'.ucfirst($composant).$nic.'Use'] == "oui") ? true : false;; |
---|
264 | $r = '<table><tr>'.$indentationHTML.'<td'.($recursive_indent ? ' class="widgy_included"' : '').'>'; |
---|
265 | $r .= '<table><tr><th><a class="'.get_widget_class($over, $on, 'widgy').'" href="?exec=acs&onglet=composants&composant='.$composant.($nic ? '&nic='.$nic : '').'"'.$titleHTML.'>'.widget_icon($composant, $nic, 10).' '.$lbl.'</a></th></tr>'; |
---|
266 | $r .= $content; |
---|
267 | $r .= '</table></td></tr></table>'; |
---|
268 | return $r; |
---|
269 | } |
---|
270 | |
---|
271 | function indent($l) { |
---|
272 | for($i = 0; $i < $l; $i++) { |
---|
273 | $r .= ' '; |
---|
274 | } |
---|
275 | return $r; |
---|
276 | } |
---|
277 | |
---|
278 | function compare_taille($a, $b) { |
---|
279 | if (strlen($a) == strlen($b)) { |
---|
280 | return 0; |
---|
281 | } |
---|
282 | return (strlen($a) > strlen($b)) ? -1 : 1; |
---|
283 | } |
---|
284 | |
---|
285 | function liste_balises() { |
---|
286 | $balises_acs = 'INTRO, ACS_CHEMIN, ACS_DERNIERE_MODIF, HEADER_COMPOSANTS, PINCEAU, VAR, ACS_VERSION, ACS_RELEASE'; |
---|
287 | |
---|
288 | $balises_spip = 'ANCRE_PAGINATION, ARRAY, ANCRE_PAGINATION, ARRAY, BIO, CACHE, CHAPO, CHARSET, CHEMIN, COMPTEUR_BOUCLE, CONFIG, DATE, DATE_MODIF, DATE_NOUVEAUTES, DATE_REDAC, DEBUT_SURLIGNE, DESCRIPTIF, DESCRIPTIF_SITE_SPIP, DISTANT, DOSSIER_SQUELETTE, EDIT, EMAIL, EMAIL_WEBMASTER, EMBED_DOCUMENT, ENV, EVAL, EXPOSE, EXPOSER, FICHIER, FIN_SURLIGNE, FORMULAIRE_ADMIN, FORMULAIRE_ECRIRE_AUTEUR, FORMULAIRE_FORUM, FORMULAIRE_INSCRIPTION, FORMULAIRE_RECHERCHE, FORMULAIRE_SIGNATURE, FORMULAIRE_SITE, GET, GRAND_TOTAL, HAUTEUR, HTTP_HEADER, ID_ARTICLE, ID_AUTEUR, ID_BREVE, ID_DOCUMENT, ID_FORUM, ID_GROUPE, ID_MOT, ID_PARENT, ID_RUBRIQUE, ID_SECTEUR, ID_SIGNATURE, ID_SYNDIC, ID_SYNDIC_ARTICLE, ID_THREAD, INCLURE, INSERT_HEAD, INTRODUCTION, IP, LANG, LANG_DIR, LANG_LEFT, LANG_RIGHT, LARGEUR, LESAUTEURS, LOGIN_PRIVE, LOGIN_PUBLIC, LOGO_ARTICLE, LOGO_ARTICLE_NORMAL, LOGO_ARTICLE_RUBRIQUE, LOGO_ARTICLE_SURVOL, LOGO_AUTEUR, LOGO_AUTEUR_NORMAL, LOGO_AUTEUR_SURVOL, LOGO_BREVE, LOGO_BREVE_RUBRIQUE, LOGO_DOCUMENT, LOGO_MOT, LOGO_RUBRIQUE, LOGO_RUBRIQUE_NORMAL, LOGO_RUBRIQUE_SURVOL, LOGO_SITE, LOGO_SITE_SPIP, MENU_LANG, MENU_LANG_ECRIRE, MESSAGE, MIME_TYPE, MODELE, NOM, NOM_SITE, NOM_SITE_SPIP, NOTES, PAGINATION, PARAMETRES_FORUM, PETITION, PGP, PIPELINE, POINTS, POPULARITE, POPULARITE_ABSOLUE, POPULARITE_MAX, POPULARITE_SITE, PS, PUCE, RECHERCHE, SELF, SET, SOURCE, SOUSTITRE, SPIP_CRON, SPIP_VERSION, SQUELETTE, SURTITRE, TAGS, TAILLE, TEXTE, TITRE, TOTAL_BOUCLE, TOTAL_UNIQUE, TYPE, TYPE_DOCUMENT, URL_ACTION_AUTEUR, URL_ARTICLE, URL_AUTEUR, URL_BREVE, URL_DOCUMENT, URL_FORUM, URL_LOGOUT, URL_MOT, URL_PAGE, URL_RUBRIQUE, URL_SITE, URL_SITE_SPIP, URL_SOURCE, URL_SYNDIC, VISITES'; |
---|
289 | return $balises_acs.', '.$balises_spip; |
---|
290 | } |
---|
291 | ?> |
---|