[SPIP][PLUGINS] v3.0-->v3.2
[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:"' . $config['selecteur_galerie']
72 . '",sel_c:"' . $config['selecteur_commun']
73 . '",trans:"' . $config['transition']
74 . '",speed:"' . $config['speed']
75 . '",ssSpeed:"' . $config['slideshow_speed']
76 . '",maxW:"' . $config['maxWidth']
77 . '",maxH:"' . $config['maxHeight']
78 . '",minW:"' . $config['minWidth']
79 . '",minH:"' . $config['minHeight']
80 . '",opa:"' . $config['opacite']
81 . '",str_ssStart:"' . unicode2charset(html2unicode(_T('mediabox:boxstr_slideshowStart')))
82 . '",str_ssStop:"' . unicode2charset(html2unicode(_T('mediabox:boxstr_slideshowStop')))
83 . '",str_cur:"' . _T('mediabox:boxstr_current', array('current' => '{current}', 'total' => '{total}'))
84 . '",str_prev:"' . _T('mediabox:boxstr_previous')
85 . '",str_next:"' . _T('mediabox:boxstr_next')
86 . '",str_close:"' . _T('mediabox:boxstr_close')
87 . '",splash_url:"' . $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 (match($extension, 'gif|png|jpg|jpeg')) {
93 $configmediabox .= 'var box_settings_iframe = false;' . "\n";
94 } else {
95 $configmediabox .= 'var box_settings_splash_width = "' . $config['splash_width'] . '";
96 var box_settings_splash_height = "' . $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
106 function mediabox_timestamp($fichier) {
107 if ($m = filemtime($fichier)) {
108 return "$fichier?$m";
109 }
110
111 return $fichier;
112 }
113
114 function mediabox_insert_head($flux) {
115 $config = mediabox_config();
116 if ($config['active'] == 'oui') {
117 $flux .= '
118 <script src="' . mediabox_timestamp(find_in_path('javascript/jquery.colorbox.js')) . '" type="text/javascript"></script>
119 <script src="' . mediabox_timestamp(find_in_path('javascript/spip.mediabox.js')) . '" type="text/javascript"></script>';
120 if ($config['splash_url']) {
121 $flux .= '<script src="' . mediabox_timestamp(find_in_path('javascript/splash.mediabox.js')) . '" type="text/javascript"></script>';
122 }
123 }
124
125 return $flux;
126 }
127
128 function mediabox_jquery_plugins($plugins) {
129 $config = mediabox_config();
130 if ($config['splash_url']) {
131 $plugins[] = 'javascript/js.cookie.js';
132 }
133
134 return $plugins;
135 }