[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins-dist / compagnon / compagnon_pipelines.php
1 <?php
2
3 /**
4 * Utilisations de pipelines
5 *
6 * @package SPIP\Compagnon\Pipelines
7 **/
8
9 if (!defined('_ECRIRE_INC_VERSION')) {
10 return;
11 }
12
13
14 /**
15 * Ajoute les aides du compagnon sur le pipeline affiche milieu
16 *
17 * @pipeline affiche_milieu
18 *
19 * @param array $flux
20 * Données du pipeline
21 * @return array
22 * Données du pipeline
23 **/
24 function compagnon_affiche_milieu($flux) {
25 return compagnonage($flux, 'affiche_milieu');
26 }
27
28 /**
29 * Ajoute les aides du compagnon sur le pipeline affiche gauche
30 *
31 * @pipeline affiche_gauche
32 *
33 * @param array $flux
34 * Données du pipeline
35 * @return array
36 * Données du pipeline
37 **/
38 function compagnon_affiche_gauche($flux) {
39 return compagnonage($flux, 'affiche_gauche');
40 }
41
42 /**
43 * Ajoute les aides du compagnon sur le pipeline affiche droite
44 *
45 * @pipeline affiche_droite
46 *
47 * @param array $flux
48 * Données du pipeline
49 * @return array
50 * Données du pipeline
51 **/
52 function compagnon_affiche_droite($flux) {
53 return compagnonage($flux, 'affiche_droite');
54 }
55
56 /**
57 * Ajoute l'aide du compagnon dans un pipeline
58 *
59 * Les aides sont ajoutées
60 * - si la config le permet
61 * - si l'aide n'a pas déjà été validée par le visiteur
62 *
63 * @pipeline_appel compagnon_messages
64 *
65 * @param array $flux
66 * Flux d'informations transmises au pipeline
67 * @param string $pipeline
68 * Nom du pipeline d'origine
69 * @return array $flux
70 * Le flux éventuellement complété de l'aide du compagnon
71 **/
72 function compagnonage($flux, $pipeline) {
73
74 // pas de compagnon souhaite ?
75 include_spip('inc/config');
76 if (lire_config('compagnon/config/activer') == 'non') {
77 return $flux;
78 }
79
80 $moi = $GLOBALS['visiteur_session'];
81 $deja_vus = lire_config('compagnon/' . $moi['id_auteur']);
82
83 $flux['args']['pipeline'] = $pipeline;
84 $flux['args']['deja_vus'] = $deja_vus;
85 $aides = pipeline('compagnon_messages', array('args' => $flux['args'], 'data' => array()));
86
87 if (!$aides) {
88 return $flux;
89 }
90
91 $ajouts = '';
92
93 foreach ($aides as $aide) {
94 // restreindre l'affichage par statut d'auteur
95 $ok = true;
96 if (isset($aide['statuts']) and $statuts = $aide['statuts']) {
97 $ok = false;
98 if (!is_array($statuts)) {
99 $statuts = array($statuts);
100 }
101 if (in_array('webmestre', $statuts) and ($moi['webmestre'] == 'oui')) {
102 $ok = true;
103 } elseif (in_array($moi['statut'], $statuts)) {
104 $ok = true;
105 }
106 }
107
108 // si c'est ok, mais que l'auteur a deja lu ca. On s'arrete.
109 if ($ok and is_array($deja_vus) and isset($deja_vus[$aide['id']]) and $deja_vus[$aide['id']]) {
110 $ok = false;
111 }
112
113 if ($ok) {
114 // demande d'un squelette
115 if (isset($aide['inclure']) and $inclure = $aide['inclure']) {
116 unset($aide['inclure']);
117 $ajout = recuperer_fond($inclure, array_merge($flux['args'], $aide), array('ajax' => true));
118 } // sinon les textes sont fournis
119 else {
120 $ajout = recuperer_fond('compagnon/_boite', $aide, array('ajax' => true));
121 }
122
123 $ajouts .= $ajout;
124 }
125 }
126
127 // ajout de nos trouvailles
128 if ($ajouts) {
129 $twinkle = find_in_path('prive/javascript/jquery.twinkle.js');
130 $ajouts .= <<<JS
131 <script type="text/javascript">
132 jQuery.getScript('$twinkle',function(){
133 jQuery(function(){
134 var options = {
135 "effect": "drop",
136 "effectOptions": {
137 "color": "rgba(255,96,96,1)",
138 "radius": 50
139 }
140 };
141 jQuery('.compagnon .target').each(function(){
142 var target = jQuery(this).attr('data-target');
143 var delay = 0;
144 jQuery(this).mousemove(function(){
145 if (!delay) {
146 delay=1; setTimeout(function(){delay=0;}, 800);
147 jQuery(target).twinkle(options);
148 }
149 });
150 });
151 });
152 });
153 </script>
154 JS;
155
156 $flux['data'] = $ajouts . $flux['data'];
157 }
158
159 return $flux;
160 }