1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * Déclarations de fonctions servant à la construction du javascript |
---|
5 | * |
---|
6 | * @plugin Porte Plume pour SPIP |
---|
7 | * @license GPL |
---|
8 | * @package SPIP\PortePlume\Javascript |
---|
9 | **/ |
---|
10 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
11 | |
---|
12 | /** |
---|
13 | * Retourne la définition de la barre markitup désignée. |
---|
14 | * (cette déclaration est au format json) |
---|
15 | * |
---|
16 | * Deux pipelines 'porte_plume_pre_charger' et 'porte_plume_charger' |
---|
17 | * permettent de récuperer l'objet de classe Barre_outil |
---|
18 | * avant son export en json pour modifier des elements. |
---|
19 | * |
---|
20 | * @pipeline_appel porte_plume_barre_pre_charger |
---|
21 | * Charge des nouveaux boutons au besoin |
---|
22 | * @pipeline_appel porte_plume_barre_charger |
---|
23 | * Affiche ou cache certains boutons |
---|
24 | * |
---|
25 | * @return string Déclaration json |
---|
26 | */ |
---|
27 | function porte_plume_creer_json_markitup(){ |
---|
28 | // on recupere l'ensemble des barres d'outils connues |
---|
29 | include_spip('porte_plume_fonctions'); |
---|
30 | if (!$sets = barre_outils_liste()) { |
---|
31 | return null; |
---|
32 | } |
---|
33 | |
---|
34 | // 1) On initialise tous les jeux de barres |
---|
35 | $barres = array(); |
---|
36 | foreach($sets as $set) { |
---|
37 | if (($barre = barre_outils_initialiser($set)) AND is_object($barre)) |
---|
38 | $barres[$set] = $barre; |
---|
39 | } |
---|
40 | |
---|
41 | // 2) Préchargement |
---|
42 | |
---|
43 | /** |
---|
44 | * Charger des nouveaux boutons au besoin |
---|
45 | * |
---|
46 | * @example |
---|
47 | * $barre = &$flux['spip']; |
---|
48 | * $barre->ajouterApres('bold',array(params)); |
---|
49 | * $barre->ajouterAvant('bold',array(params)); |
---|
50 | * |
---|
51 | * $bold = $barre->get('bold'); |
---|
52 | * $bold['id'] = 'bold2'; |
---|
53 | * $barre->ajouterApres('italic',$bold); |
---|
54 | * @pipeline_appel porte_plume_barre_pre_charger |
---|
55 | */ |
---|
56 | $barres = pipeline('porte_plume_barre_pre_charger', $barres); |
---|
57 | |
---|
58 | |
---|
59 | // 3) Chargement |
---|
60 | |
---|
61 | /** |
---|
62 | * Cacher ou afficher certains boutons au besoin |
---|
63 | * |
---|
64 | * @example |
---|
65 | * $barre = &$flux['spip']; |
---|
66 | * $barre->afficher('bold'); |
---|
67 | * $barre->cacher('bold'); |
---|
68 | * |
---|
69 | * $barre->cacherTout(); |
---|
70 | * $barre->afficher(array('bold','italic','header1')); |
---|
71 | * @pipeline_appel porte_plume_barre_charger |
---|
72 | */ |
---|
73 | $barres = pipeline('porte_plume_barre_charger', $barres); |
---|
74 | |
---|
75 | |
---|
76 | // 4 On crée les jsons |
---|
77 | $json = ""; |
---|
78 | foreach($barres as $set=>$barre) { |
---|
79 | $json .= $barre->creer_json(); |
---|
80 | } |
---|
81 | return $json; |
---|
82 | } |
---|