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