c938b2fb8582e95ee0ce072b8d07049df63ecb98
[lhc/web/www.git] / www / plugins-dist / mediabox / mediabox_pipelines.php
1 <?php
2
3 if (!defined('_ECRIRE_INC_VERSION')) {
4 return;
5 }
6
7 function mediabox_config($public = null) {
8 include_spip('inc/filtres');
9 include_spip('inc/config');
10 $config = lire_config('mediabox', array());
11
12 $config = array_merge(array(
13 'active' => 'oui',
14 'traiter_toutes_images' => 'oui',
15 'selecteur_galerie' => '#documents_portfolio a[type=\'image/jpeg\'],#documents_portfolio a[type=\'image/png\'],#documents_portfolio a[type=\'image/gif\']',
16 'selecteur_commun' => '.mediabox',
17 'splash_url' => '',
18 'splash_width' => '600px',
19 'splash_height' => '90%',
20 'skin' => 'black-striped',
21 'transition' => 'elastic',
22 'speed' => '200',
23 'maxWidth' => '90%',
24 'maxHeight' => '90%',
25 'minWidth' => '400px',
26 'minHeight' => '',
27 'slideshow_speed' => '2500',
28 'opacite' => '0.9',
29 ), $config);
30
31 if ((is_null($public) and test_espace_prive()) or $public === false) {
32 $config = array_merge($config, array(
33 'active' => 'oui',
34 'selecteur_galerie' => '#portfolios a[type^=\'image/\']',
35 'selecteur_commun' => '.mediabox, .iconifier a[href$=jpg],.iconifier a[href$=png],.iconifier a[href$=gif]',
36 'splash_url' => '',
37 'skin' => 'white-shadow',
38 'maxWidth' => '90%',
39 'maxHeight' => '95%',
40 'minWidth' => '600px',
41 'minHeight' => '300px',
42 'opacite' => '0.9',
43 ));
44 }
45
46 // Gerer aussi les liens internes de SPIP
47 if (!test_espace_prive() and $config['splash_url']) {
48 include_spip('inc/filtres_ecrire');
49 $config['splash_url'] = url_absolue(extraire_attribut(lien_article_virtuel($config['splash_url']), 'href'));
50 }
51
52 // charger la config du theme uniquement dans le public
53 if (!test_espace_prive() and include_spip('colorbox/' . $config['skin'] . '/mediabox_config_theme')) {
54 $config_theme = mediabox_config_theme();
55 $config = array_merge($config, $config_theme);
56 }
57
58 return $config;
59 }
60
61 function mediabox_insert_head_css($flux) {
62 $config = mediabox_config();
63 if ($config['active'] == 'oui'
64 and $f = find_in_path((test_espace_prive() ? 'prive/' : '') . 'colorbox/' . $config['skin'] . '/colorbox.css')) {
65 $flux .= '<link rel="stylesheet" href="' . direction_css($f) . '" type="text/css" media="all" />';
66 /**
67 * Initialiser la config de la mediabox
68 */
69 $configmediabox = '<script type="text/javascript">/* <![CDATA[ */
70 var box_settings = {tt_img:' . ($config['traiter_toutes_images'] == 'oui' ? 'true' : 'false')
71 . ',sel_g:"' . mediabox_quote_js_param($config['selecteur_galerie'])
72 . '",sel_c:"' . mediabox_quote_js_param($config['selecteur_commun'])
73 . '",trans:"' . mediabox_quote_js_param($config['transition'])
74 . '",speed:"' . mediabox_quote_js_param($config['speed'])
75 . '",ssSpeed:"' . mediabox_quote_js_param($config['slideshow_speed'])
76 . '",maxW:"' . mediabox_quote_js_param($config['maxWidth'])
77 . '",maxH:"' . mediabox_quote_js_param($config['maxHeight'])
78 . '",minW:"' . mediabox_quote_js_param($config['minWidth'])
79 . '",minH:"' . mediabox_quote_js_param($config['minHeight'])
80 . '",opa:"' . mediabox_quote_js_param($config['opacite'])
81 . '",str_ssStart:"' . mediabox_quote_js_param(unicode2charset(html2unicode(_T('mediabox:boxstr_slideshowStart'))))
82 . '",str_ssStop:"' . mediabox_quote_js_param(unicode2charset(html2unicode(_T('mediabox:boxstr_slideshowStop'))))
83 . '",str_cur:"' . mediabox_quote_js_param(_T('mediabox:boxstr_current', array('current' => '{current}', 'total' => '{total}')))
84 . '",str_prev:"' . mediabox_quote_js_param(_T('mediabox:boxstr_previous'))
85 . '",str_next:"' . mediabox_quote_js_param(_T('mediabox:boxstr_next'))
86 . '",str_close:"' . mediabox_quote_js_param(_T('mediabox:boxstr_close'))
87 . '",splash_url:"' . mediabox_quote_js_param($config['splash_url'])
88 . '"};' . "\n";
89 // Si c'est une image, on la chargera avec une redimentionnement automatique
90 // Sinon, chargement dans une iframe
91 $extension = pathinfo($config['splash_url'], PATHINFO_EXTENSION);
92 if (in_array($extension, array('gif', 'png', 'jpg', 'jpeg'))) {
93 $configmediabox .= 'var box_settings_iframe = false;' . "\n";
94 } else {
95 $configmediabox .= 'var box_settings_splash_width = "' . mediabox_quote_js_param($config['splash_width']) . '";
96 var box_settings_splash_height = "' . mediabox_quote_js_param($config['splash_height']) . '";' . "\n";
97 $configmediabox .= 'var box_settings_iframe = true;' . "\n";
98 }
99 $flux = $configmediabox . '/* ]]> */</script>' . "\n" . $flux;
100 }
101
102 return $flux;
103 }
104
105 function mediabox_quote_js_param($valeur) {
106 return str_replace(["'", "<"], ["\\'", "&lt;"], $valeur);
107 }
108
109 function mediabox_timestamp($fichier) {
110 if ($m = filemtime($fichier)) {
111 return "$fichier?$m";
112 }
113
114 return $fichier;
115 }
116
117 function mediabox_insert_head($flux) {
118 $config = mediabox_config();
119 if ($config['active'] == 'oui') {
120 $flux .= '
121 <script src="' . mediabox_timestamp(find_in_path('javascript/jquery.colorbox.js')) . '" type="text/javascript"></script>
122 <script src="' . mediabox_timestamp(find_in_path('javascript/spip.mediabox.js')) . '" type="text/javascript"></script>';
123 if ($config['splash_url']) {
124 $flux .= '<script src="' . mediabox_timestamp(find_in_path('javascript/splash.mediabox.js')) . '" type="text/javascript"></script>';
125 }
126 }
127
128 return $flux;
129 }
130
131 function mediabox_jquery_plugins($plugins) {
132 $config = mediabox_config();
133 if ($config['splash_url']) {
134 $plugins[] = 'javascript/js.cookie.js';
135 }
136
137 return $plugins;
138 }