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

Last change on this file since 10021 was 10021, checked in by binaryworld, 13 years ago

For Piwigo 2.1.6 compatibility

File size: 6.5 KB
RevLine 
[10016]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'}
[10021]97                /* Not available for Piwigo 2.1.6
[10016]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                );
[10021]106                */
107                $content .= '<script src="themes/default/js/scripts.js" type="text/javascript"></script>';
[10016]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
142
143class ModalOverlayLibFactory {
144       
145       
146        public static function getFactoryPath() {
147                return dirname(__FILE__) .DS. 'libs';
148        }
149       
150        public static function getOverlayLibPath($libName) {
151                return self::getFactoryPath() .DS. $libName;
152        }
153       
154        public static function getFactoryUrl() {
155                return get_root_url() .'plugins/'. basename(dirname(__FILE__)) .'/libs';
156        }
157       
158        public static function getInstalledOverlayLibs() {
159                $libs = array();
160                if (MediaboxAdvancedWrapper::isInstalled() === true) $libs[] =  MediaboxAdvancedWrapper::getName();
161                if (ShadowboxWrapper::isInstalled() === true) $libs[] =  ShadowboxWrapper::getName();
162                return $libs;
163        }
164       
165        public static function getDefaultOverlayLib() {
166                return MediaboxAdvancedWrapper::getName();
167        }
168       
169        public static function getDefaultOverlayTheme() {
170                $themes = MediaboxAdvancedWrapper::getThemes();
171                return (empty($themes)) ? null : $themes[0];
172        }
173       
174        public static function createModalOverlayLib($libName) {
175                if (0 === strcmp($libName, MediaboxAdvancedWrapper::getName())) {
176                        return new MediaboxAdvancedWrapper();
177                } else if (0 === strcmp($libName, ShadowboxWrapper::getName())) {
178                        return new ShadowboxWrapper();
179                }
180                return null;
181        }
182       
183        public static function getDirectoriesFromPath($path) {
184                static $weeds = array('.', '..');
185                $directories = array_diff(scandir($path), $weeds);
186                $dirs = array(); 
187                foreach($directories as $value) {
188                        if(is_dir($path .DS. $value)) {
189                                $dirs[] = $value;
190                        }
191                }
192                return $dirs;
193        }
194}
195
196?>
Note: See TracBrowser for help on using the repository browser.