source: extensions/Shadogo/trunk/overlaylibs.inc.php @ 14986

Last change on this file since 14986 was 14986, checked in by binaryworld, 12 years ago

v0.2.0

File size: 10.1 KB
Line 
1<?php
2/*
3Plugin : Shadogo
4Plugin URI: http://binaryworld.hd.free.fr/
5*/
6
7if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
8
9interface iModalOverlayLib {
10        static public function getName();
11        static public function isInstalled();
12        static public function getThemes();
13        public function getPlayerUrl();
14        public function getFlashVarsTemplate();
15        public function getDefaultLinkRelationship();
16        public function appendHeaderContent($template, $tpl_var, $config);
17        public function getCloseThumbnailJavaScript();
18}
19
20class ShadowboxWrapper implements iModalOverlayLib {
21        public static $LIB_NAME = 'shadowbox';
22       
23        static function getName() {
24                return self::$LIB_NAME;
25        }
26       
27        static public function isInstalled() {
28                $filename = ModalOverlayLibFactory::getFactoryPath() .DS. self::getName() .DS. 'shadowbox.js';
29                return file_exists($filename);
30        }
31       
32        public function getFlashVarsTemplate() {
33                return 'file={$VIDEO_URL}&image={$SRC_IMG}&controlbar.position=over';
34        }
35       
36        public function getPlayerUrl() {
37                $path = ModalOverlayLibFactory::getFactoryUrl() .'/'. self::getName() .'/player.swf';
38                return $path;
39        }
40
41        public function getDefaultLinkRelationship() {
42                 return 'shadowbox';
43        }
44       
45        public function appendHeaderContent($template, $tpl_var, $config) {
46                $libPath = ModalOverlayLibFactory::getFactoryUrl() .'/'. self::getName(); 
47               
48                $scriptContent = 'var shadogoOverlayWnd = Shadowbox; Shadowbox.init();';
49                $headContent  = '<link rel="stylesheet" type="text/css" href="'. $libPath .'/shadowbox.css">';
50                $headContent .= '<script type="text/javascript" src="'. $libPath .'/shadowbox.js"></script>';
51                $headContent .= '<script type="text/javascript">'. $scriptContent .'</script>';
52               
53                $template->append($tpl_var, $headContent);
54        }
55       
56        public function getCloseThumbnailJavaScript() {
57                return 'parent.window.Shadowbox.close(); return false;';
58        }
59
60        static public function getThemes() {
61                return array();
62        }
63}
64
65class MediaboxAdvancedWrapper implements iModalOverlayLib {
66        public static $LIB_NAME = 'mediaboxAdvanced';
67
68        static function getName() {
69                return self::$LIB_NAME;
70        }
71
72        static public function isInstalled() {
73                $filename = ModalOverlayLibFactory::getFactoryPath() .DS. self::getName() .DS. 'mediaboxAdv-1.3.4b.js';
74                return file_exists($filename);
75        }
76       
77        public function getFlashVarsTemplate() {
78                return 'mediaURL={$VIDEO_URL}&teaserURL={$SRC_IMG}&allowSmoothing=true&autoPlay=false&buffer=6&showTimecode=true&loop=false&controlColor=0xFFFFFF&controlBackColor=0x000000&scaleIfFullScreen=true&showScalingButton=true&defaultVolume=100&crop=false';
79        }
80       
81        public function getPlayerUrl() {
82                $path = ModalOverlayLibFactory::getFactoryUrl() .'/'. self::getName() .'/NonverBlaster.swf';
83                return $path;
84        }
85       
86        public function getDefaultLinkRelationship() {
87                return 'lightbox';
88        }
89       
90        public function appendHeaderContent($template, $tpl_var, $config) {
91                global $page;
92                $libPath = ModalOverlayLibFactory::getFactoryUrl() .'/'. self::getName(); 
93                $content = '';
94
95                // add script for services (used for "add to caddie")
96                //{combine_script id='core.scripts' load='async' path='themes/default/js/scripts.js'}
97                /* Not available for Piwigo 2.1.6
98                $template->func_combine_script(
99                        array(
100                                'id' => 'core.scripts',
101                                'load' => 'async',
102                                'path' => 'themes/default/js/scripts.js'
103                        ),
104                        $template->smarty
105                );
106                */
107                $content .= '<script src="themes/default/js/scripts.js" type="text/javascript"></script>';
108               
109                $theme = $config->modalOverlayTheme;
110                if ( !empty( $theme )) {
111                        $content .= '<link rel="stylesheet" href="'. $libPath .'/themes/style.css" type="text/css" media="screen" />';
112                        $content .= '<link rel="stylesheet" href="'. $libPath .'/themes/'. $theme .'/style.css" type="text/css" media="screen" />';
113                }
114
115                $content .= '<script src="'. $libPath .'/mootools-1.2.5-core-yc.js" type="text/javascript"></script>';
116                $content .= '<script src="'. $libPath .'/Quickie.js" type="text/javascript"></script>';
117                $content .= '<script src="'. $libPath .'/mediaboxAdv-1.3.4b.js" type="text/javascript"></script>';
118               
119                $content .= '<script type="text/javascript">var ShadogoOverlayWnd=Mediabox; shadogoOptions = {';
120                $content .= 'piwigoRootUrl: "'. get_root_url() .'"';
121                if (isset($page['category'])) {
122                $content .= ', piwigoCategory: '. $page['category']['id'];
123                }
124                $content .= ', displayAddToBasket: '. (int) (is_admin() && $config->addToBasket && isset($page['category']));
125                $content .= ', displayFavorite: '. (int) (!is_a_guest() && $config->favoritePicture && isset($page['category']));
126                $content .= ', displayHdPicture: '. (int) $config->hdPicture;
127                $content .= ', displayDownload: '. (int) $config->downloadPicture;
128                $content .= '};</script>';
129               
130                $template->append($tpl_var, $content);
131        }
132
133        public function getCloseThumbnailJavaScript() {
134                return 'parent.window.Shadowbox.close(); return false;';
135        }
136       
137        static public function getThemes() {
138                return ModalOverlayLibFactory::getDirectoriesFromPath(ModalOverlayLibFactory::getFactoryPath() .DS. self::getName() .DS. 'themes');
139        }
140}
141
142class MediaboxAdvanced15Wrapper implements iModalOverlayLib {
143        public static $LIB_NAME = 'mediaboxAdvanced_1_5_x';
144
145        static function getName() {
146                return self::$LIB_NAME;
147        }
148
149        static public function isInstalled() {
150                $filename = ModalOverlayLibFactory::getFactoryPath() .DS. self::getName() .DS. 'mediaboxAdv-1.5.4.js';
151                return file_exists($filename);
152        }
153
154        public function getFlashVarsTemplate() {
155                //return 'mediaURL={$VIDEO_URL}&teaserURL={$SRC_IMG}&allowSmoothing=true&autoPlay=false&buffer=6&showTimecode=true&loop=false&controlColor=0xFFFFFF&controlBackColor=0x000000&scaleIfFullScreen=true&showScalingButton=true&defaultVolume=100&crop=false';
156                return 'file={$VIDEO_URL}&image={$SRC_IMG}&controlbar.position=over';
157        }
158
159        public function getPlayerUrl() {
160                //$path = ModalOverlayLibFactory::getFactoryUrl() .'/'. self::getName() .'/NonverBlaster.swf';
161                $path = ModalOverlayLibFactory::getFactoryUrl() .'/'. self::getName() .'/player.swf';
162                return $path;
163        }
164
165        public function getDefaultLinkRelationship() {
166                return 'lightbox';
167        }
168
169        public function appendHeaderContent($template, $tpl_var, $config) {
170                global $page;
171                $libPath = ModalOverlayLibFactory::getFactoryUrl() .'/'. self::getName();
172                $content = '';
173
174                // add script for services (used for "add to caddie")
175                //{combine_script id='core.scripts' load='async' path='themes/default/js/scripts.js'}
176                /* Not available for Piwigo 2.1.6
177                 $template->func_combine_script(
178                array(
179                'id' => 'core.scripts',
180                'load' => 'async',
181                'path' => 'themes/default/js/scripts.js'
182                ),
183                $template->smarty
184                );
185                */
186                $content .= '<script src="themes/default/js/scripts.js" type="text/javascript"></script>';
187
188                $theme = $config->modalOverlayTheme;
189                if ( !empty( $theme )) {
190                        //$content .= '<link rel="stylesheet" href="'. $libPath .'/themes/style.css" type="text/css" media="screen" />';
191                        $content .= '<link rel="stylesheet" href="'. $libPath .'/themes/'. $theme .'/style.css" type="text/css" media="screen,projection" />';
192                }
193
194                //$content .= '<script src="'. $libPath .'/mootools-core-1.3.2.js" type="text/javascript"></script>';
195                $content .= '<script src="'. $libPath .'/mootools-core-1.4.5.js" type="text/javascript"></script>';
196                $content .= '<script src="'. $libPath .'/Quickie.js" type="text/javascript"></script>';
197                $content .= '<script src="'. $libPath .'/mediaboxAdv-1.5.4.js" type="text/javascript"></script>';
198
199                $content .= '<script type="text/javascript">var ShadogoOverlayWnd=Mediabox; shadogoOptions = {';
200                $content .= 'piwigoRootUrl: "'. get_root_url() .'"';
201                if (isset($page['category'])) {
202                        $content .= ', piwigoCategory: '. $page['category']['id'];
203                }
204                $content .= ', displayAddToBasket: '. (int) (is_admin() && $config->addToBasket && isset($page['category']));
205                $content .= ', displayFavorite: '. (int) (!is_a_guest() && $config->favoritePicture && isset($page['category']));
206                $content .= ', displayHdPicture: '. (int) $config->hdPicture;
207                $content .= ', displayDownload: '. (int) $config->downloadPicture;
208                $content .= '};</script>';
209
210                $template->append($tpl_var, $content);
211        }
212
213        public function getCloseThumbnailJavaScript() {
214                return 'parent.window.Shadowbox.close(); return false;';
215        }
216
217        static public function getThemes() {
218                return ModalOverlayLibFactory::getDirectoriesFromPath(ModalOverlayLibFactory::getFactoryPath() .DS. self::getName() .DS. 'themes');
219        }
220}
221
222
223class ModalOverlayLibFactory {
224       
225       
226        public static function getFactoryPath() {
227                return dirname(__FILE__) .DS. 'libs';
228        }
229       
230        public static function getOverlayLibPath($libName) {
231                return self::getFactoryPath() .DS. $libName;
232        }
233       
234        public static function getFactoryUrl() {
235                return get_root_url() .'plugins/'. basename(dirname(__FILE__)) .'/libs';
236        }
237       
238        public static function getInstalledOverlayLibs() {
239                $libs = array();
240                if (MediaboxAdvancedWrapper::isInstalled() === true) $libs[] =  MediaboxAdvancedWrapper::getName();
241                if (MediaboxAdvanced15Wrapper::isInstalled() === true) $libs[] =  MediaboxAdvanced15Wrapper::getName();
242                if (ShadowboxWrapper::isInstalled() === true) $libs[] =  ShadowboxWrapper::getName();
243                return $libs;
244        }
245       
246        public static function getDefaultOverlayLib() {
247                return MediaboxAdvancedWrapper::getName();
248        }
249       
250        public static function getDefaultOverlayTheme() {
251                $themes = MediaboxAdvancedWrapper::getThemes();
252                return (empty($themes)) ? null : $themes[0];
253        }
254       
255        public static function createModalOverlayLib($libName) {
256                if (0 === strcmp($libName, MediaboxAdvancedWrapper::getName())) {
257                        return new MediaboxAdvancedWrapper();
258                } else if (0 === strcmp($libName, MediaboxAdvanced15Wrapper::getName())) {
259                        return new MediaboxAdvanced15Wrapper();
260                } else if (0 === strcmp($libName, ShadowboxWrapper::getName())) {
261                        return new ShadowboxWrapper();
262                }
263                return null;
264        }
265       
266        public static function getDirectoriesFromPath($path) {
267                static $weeds = array('.', '..');
268                $directories = array_diff(scandir($path), $weeds);
269                $dirs = array(); 
270                foreach($directories as $value) {
271                        if(is_dir($path .DS. $value)) {
272                                $dirs[] = $value;
273                        }
274                }
275                return $dirs;
276        }
277}
278
279?>
Note: See TracBrowser for help on using the repository browser.