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' and $f = find_in_path((test_espace_prive() ? "prive/" : "") . "colorbox/" . $config['skin'] . '/colorbox.css')) { |
---|
64 | $flux .= '<link rel="stylesheet" href="' . direction_css($f) . '" type="text/css" media="all" />'; |
---|
65 | /** |
---|
66 | * Initialiser la config de la mediabox |
---|
67 | */ |
---|
68 | $configmediabox = '<script type="text/javascript">/* <![CDATA[ */ |
---|
69 | var box_settings = {tt_img:' . ($config['traiter_toutes_images'] == 'oui' ? 'true' : 'false') |
---|
70 | . ',sel_g:"' . $config['selecteur_galerie'] |
---|
71 | . '",sel_c:"' . $config['selecteur_commun'] |
---|
72 | . '",trans:"' . $config['transition'] |
---|
73 | . '",speed:"' . $config['speed'] |
---|
74 | . '",ssSpeed:"' . $config['slideshow_speed'] |
---|
75 | . '",maxW:"' . $config['maxWidth'] |
---|
76 | . '",maxH:"' . $config['maxHeight'] |
---|
77 | . '",minW:"' . $config['minWidth'] |
---|
78 | . '",minH:"' . $config['minHeight'] |
---|
79 | . '",opa:"' . $config['opacite'] |
---|
80 | . '",str_ssStart:"' . unicode2charset(html2unicode(_T('mediabox:boxstr_slideshowStart'))) |
---|
81 | . '",str_ssStop:"' . unicode2charset(html2unicode(_T('mediabox:boxstr_slideshowStop'))) |
---|
82 | . '",str_cur:"' . _T('mediabox:boxstr_current', array('current' => '{current}', 'total' => '{total}')) |
---|
83 | . '",str_prev:"' . _T('mediabox:boxstr_previous') |
---|
84 | . '",str_next:"' . _T('mediabox:boxstr_next') |
---|
85 | . '",str_close:"' . _T('mediabox:boxstr_close') |
---|
86 | . '",splash_url:"' . $config['splash_url'] |
---|
87 | . '"};' . "\n"; |
---|
88 | // Si c'est une image, on la chargera avec une redimentionnement automatique |
---|
89 | // Sinon, chargement dans une iframe |
---|
90 | $extension = pathinfo($config['splash_url'], PATHINFO_EXTENSION); |
---|
91 | if (match($extension, 'gif|png|jpg|jpeg')) { |
---|
92 | $configmediabox .= 'var box_settings_iframe = false;' . "\n"; |
---|
93 | } else { |
---|
94 | $configmediabox .= 'var box_settings_splash_width = "' . $config['splash_width'] . '"; |
---|
95 | var box_settings_splash_height = "' . $config['splash_height'] . '";' . "\n"; |
---|
96 | $configmediabox .= 'var box_settings_iframe = true;' . "\n"; |
---|
97 | } |
---|
98 | $flux = $configmediabox . '/* ]]> */</script>' . "\n" . $flux; |
---|
99 | } |
---|
100 | |
---|
101 | return $flux; |
---|
102 | } |
---|
103 | |
---|
104 | |
---|
105 | function mediabox_timestamp($fichier) { |
---|
106 | if ($m = filemtime($fichier)) { |
---|
107 | return "$fichier?$m"; |
---|
108 | } |
---|
109 | |
---|
110 | return $fichier; |
---|
111 | } |
---|
112 | |
---|
113 | function mediabox_insert_head($flux) { |
---|
114 | $config = mediabox_config(); |
---|
115 | if ($config['active'] == 'oui') { |
---|
116 | |
---|
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/jquery.cookie.js'; |
---|
132 | } |
---|
133 | |
---|
134 | return $plugins; |
---|
135 | } |
---|