| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin : Shadogo |
|---|
| 4 | Plugin URI: http://binaryworld.hd.free.fr/ |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
|---|
| 8 | |
|---|
| 9 | interface 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 | |
|---|
| 20 | class 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 | |
|---|
| 65 | class 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 | $template->func_combine_script( |
|---|
| 98 | array( |
|---|
| 99 | 'id' => 'core.scripts', |
|---|
| 100 | 'load' => 'async', |
|---|
| 101 | 'path' => 'themes/default/js/scripts.js' |
|---|
| 102 | ), |
|---|
| 103 | $template->smarty |
|---|
| 104 | ); |
|---|
| 105 | |
|---|
| 106 | $theme = $config->modalOverlayTheme; |
|---|
| 107 | if ( !empty( $theme )) { |
|---|
| 108 | $content .= '<link rel="stylesheet" href="'. $libPath .'/themes/style.css" type="text/css" media="screen" />'; |
|---|
| 109 | $content .= '<link rel="stylesheet" href="'. $libPath .'/themes/'. $theme .'/style.css" type="text/css" media="screen" />'; |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | $content .= '<script src="'. $libPath .'/mootools-1.2.5-core-yc.js" type="text/javascript"></script>'; |
|---|
| 113 | $content .= '<script src="'. $libPath .'/Quickie.js" type="text/javascript"></script>'; |
|---|
| 114 | $content .= '<script src="'. $libPath .'/mediaboxAdv-1.3.4b.js" type="text/javascript"></script>'; |
|---|
| 115 | |
|---|
| 116 | $content .= '<script type="text/javascript">var ShadogoOverlayWnd=Mediabox; shadogoOptions = {'; |
|---|
| 117 | $content .= 'piwigoRootUrl: "'. get_root_url() .'"'; |
|---|
| 118 | if (isset($page['category'])) { |
|---|
| 119 | $content .= ', piwigoCategory: '. $page['category']['id']; |
|---|
| 120 | } |
|---|
| 121 | $content .= ', displayAddToBasket: '. (int) (is_admin() && $config->addToBasket && isset($page['category'])); |
|---|
| 122 | $content .= ', displayFavorite: '. (int) (!is_a_guest() && $config->favoritePicture && isset($page['category'])); |
|---|
| 123 | $content .= ', displayHdPicture: '. (int) $config->hdPicture; |
|---|
| 124 | $content .= ', displayDownload: '. (int) $config->downloadPicture; |
|---|
| 125 | $content .= '};</script>'; |
|---|
| 126 | |
|---|
| 127 | $template->append($tpl_var, $content); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | public function getCloseThumbnailJavaScript() { |
|---|
| 131 | return 'parent.window.Shadowbox.close(); return false;'; |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | static public function getThemes() { |
|---|
| 135 | return ModalOverlayLibFactory::getDirectoriesFromPath(ModalOverlayLibFactory::getFactoryPath() .DS. self::getName() .DS. 'themes'); |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | class ModalOverlayLibFactory { |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | public static function getFactoryPath() { |
|---|
| 144 | return dirname(__FILE__) .DS. 'libs'; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | public static function getOverlayLibPath($libName) { |
|---|
| 148 | return self::getFactoryPath() .DS. $libName; |
|---|
| 149 | } |
|---|
| 150 | |
|---|
| 151 | public static function getFactoryUrl() { |
|---|
| 152 | return get_root_url() .'plugins/'. basename(dirname(__FILE__)) .'/libs'; |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | public static function getInstalledOverlayLibs() { |
|---|
| 156 | $libs = array(); |
|---|
| 157 | if (MediaboxAdvancedWrapper::isInstalled() === true) $libs[] = MediaboxAdvancedWrapper::getName(); |
|---|
| 158 | if (ShadowboxWrapper::isInstalled() === true) $libs[] = ShadowboxWrapper::getName(); |
|---|
| 159 | return $libs; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | public static function getDefaultOverlayLib() { |
|---|
| 163 | return MediaboxAdvancedWrapper::getName(); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | public static function getDefaultOverlayTheme() { |
|---|
| 167 | $themes = MediaboxAdvancedWrapper::getThemes(); |
|---|
| 168 | return (empty($themes)) ? null : $themes[0]; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | public static function createModalOverlayLib($libName) { |
|---|
| 172 | if (0 === strcmp($libName, MediaboxAdvancedWrapper::getName())) { |
|---|
| 173 | return new MediaboxAdvancedWrapper(); |
|---|
| 174 | } else if (0 === strcmp($libName, ShadowboxWrapper::getName())) { |
|---|
| 175 | return new ShadowboxWrapper(); |
|---|
| 176 | } |
|---|
| 177 | return null; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | public static function getDirectoriesFromPath($path) { |
|---|
| 181 | static $weeds = array('.', '..'); |
|---|
| 182 | $directories = array_diff(scandir($path), $weeds); |
|---|
| 183 | $dirs = array(); |
|---|
| 184 | foreach($directories as $value) { |
|---|
| 185 | if(is_dir($path .DS. $value)) { |
|---|
| 186 | $dirs[] = $value; |
|---|
| 187 | } |
|---|
| 188 | } |
|---|
| 189 | return $dirs; |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | ?> |
|---|