[10016] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: Shadogo |
---|
[14889] | 4 | Version: 0.1.12 |
---|
[10016] | 5 | Description: Display pictures, videos and piwigo pages in modal overlay window. |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=521 |
---|
| 7 | Author: Binaryworld |
---|
| 8 | Author URI: http://binaryworld.hd.free.fr/ |
---|
| 9 | */ |
---|
| 10 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 11 | define('SHADOGO_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
| 12 | if (!defined( 'DS')) define( 'DS', DIRECTORY_SEPARATOR ); |
---|
| 13 | load_language('plugin.lang', SHADOGO_PATH); |
---|
| 14 | |
---|
| 15 | include_once SHADOGO_PATH .'overlaylibs.inc.php'; |
---|
| 16 | include_once SHADOGO_PATH .'config.inc.php'; |
---|
| 17 | |
---|
| 18 | class Shadogo { |
---|
| 19 | |
---|
| 20 | public static $PLUGIN_ID = NULL; |
---|
| 21 | private static $_instance = NULL; |
---|
| 22 | |
---|
| 23 | private $_config; |
---|
| 24 | private $_pluginPath; |
---|
| 25 | private $_pluginURL; |
---|
| 26 | private $_overlayLibs = array(); |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * Prevent direct object creation |
---|
| 30 | */ |
---|
| 31 | final private function __construct() { } |
---|
| 32 | |
---|
| 33 | /** |
---|
| 34 | * Prevent object cloning |
---|
| 35 | */ |
---|
| 36 | final private function __clone() { } |
---|
| 37 | |
---|
| 38 | final public static function getInstance($pluginId){ |
---|
| 39 | if(null !== self::$_instance){ |
---|
| 40 | return self::$_instance; |
---|
| 41 | } |
---|
| 42 | $oldInstance = get_plugin_data($pluginId); |
---|
| 43 | |
---|
| 44 | self::$_instance = new Shadogo(); |
---|
| 45 | self::$PLUGIN_ID = $pluginId; |
---|
| 46 | //self::$_instance->loadConfig(); |
---|
| 47 | set_plugin_data(self::$PLUGIN_ID, self::$_instance); |
---|
| 48 | return self::$_instance; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | public function getPluginPath() { |
---|
| 53 | if ( !isset($this->_pluginPath) ) $this->_pluginPath = dirname(__FILE__); |
---|
| 54 | return $this->_pluginPath; |
---|
| 55 | } |
---|
| 56 | public function getPluginURL() { |
---|
| 57 | if ( !isset($this->_pluginURL) ) $this->_pluginURL = get_root_url() .'plugins/'. basename(dirname(__FILE__)); |
---|
| 58 | return $this->_pluginURL; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | public function &getConfig() { |
---|
| 62 | global $conf; |
---|
| 63 | if (isset($this->_config)) return $this->_config; |
---|
| 64 | // the config is initialized in DB during the plugin installation |
---|
| 65 | if (isset( $conf[ShadogoConfig::$CONFIG_NAME])) { |
---|
| 66 | $this->_config = new ShadogoConfig(); |
---|
| 67 | return $this->_config; |
---|
| 68 | } |
---|
| 69 | // !! Not possible if the plugin is well installed |
---|
| 70 | $this->_config = $this->getDefaultConfig(); |
---|
| 71 | return $this->_config; |
---|
| 72 | } |
---|
| 73 | public function getDefaultConfig() { |
---|
| 74 | $c = ShadogoConfig::createDefaultConfiguration(); |
---|
| 75 | return new ShadogoConfig($c); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | // |
---|
| 79 | // Modal overlay lib |
---|
| 80 | // |
---|
| 81 | public function getOverlayLib($libName = null) { |
---|
| 82 | if (empty($libName)) { |
---|
| 83 | $libName = $this->getConfig()->modalOverlayLib; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | if ( !empty( $this->_overlayLibs[$libName] )) { |
---|
| 87 | return $this->_overlayLibs[$libName]; |
---|
| 88 | } |
---|
| 89 | $this->_overlayLibs[$libName] = ModalOverlayLibFactory::createModalOverlayLib($libName); |
---|
| 90 | return $this->_overlayLibs[$libName]; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | public function getInstalledOverlayLibs() { |
---|
| 94 | return ModalOverlayLibFactory::getInstalledOverlayLibs(); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | // |
---|
| 99 | // Admin |
---|
| 100 | // |
---|
| 101 | public function onAdminMenu($menu) { |
---|
| 102 | array_push($menu, |
---|
| 103 | array( |
---|
| 104 | 'NAME' => 'Shadogo', |
---|
| 105 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/shadogo_admin.php') |
---|
| 106 | ) |
---|
| 107 | ); |
---|
| 108 | return $menu; |
---|
| 109 | |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | // |
---|
| 113 | // Site Event Management |
---|
| 114 | // |
---|
| 115 | |
---|
| 116 | public function onBeginPicture() { |
---|
| 117 | global $template; |
---|
| 118 | if ($this->getConfig()->hdPictureInOverlay === true) { |
---|
| 119 | $template->set_prefilter('default_content', 'shadogo_pictureprefilter'); |
---|
| 120 | } |
---|
| 121 | if ($this->getConfig()->slideshowInOverlay === true) { |
---|
| 122 | $template->set_prefilter('picture', 'shadogo_slideshowprefilter'); |
---|
| 123 | $template->set_prefilter('slideshow', 'shadogo_closeslideshowprefilter'); |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | public function onBeginIndex() { |
---|
| 128 | global $template; |
---|
| 129 | $test = $this->getConfig(); |
---|
| 130 | |
---|
| 131 | if ($this->getConfig()->thumbInOverlay === true) { |
---|
| 132 | $template->set_prefilter('index_thumbnails', 'shadogo_thumbprefilter'); |
---|
| 133 | } |
---|
| 134 | if ($this->getConfig()->slideshowInOverlay === true) { |
---|
| 135 | $template->set_prefilter('index', 'shadogo_slideshowprefilter'); |
---|
| 136 | $template->set_prefilter('slideshow', 'shadogo_closeslideshowprefilter'); |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | protected function assignPluginTemplateVars($template) { |
---|
| 141 | $c = $this->getConfig(); |
---|
| 142 | $template->assign(ShadogoConfig::$CONFIG_NAME, array( |
---|
| 143 | 'thumbMediaPlayerIcon' => $c->thumbMediaPlayerIcon, |
---|
| 144 | 'thumbContentIcon' => $c->thumbContentIcon, |
---|
| 145 | 'thumbContentLabel' => $c->thumbContentLabel, |
---|
| 146 | 'thumbContentInOverlay' => $c->thumbContentInOverlay, |
---|
| 147 | 'overlayLibName' => $c->modalOverlayLib, |
---|
| 148 | 'overlayLibPath' => ModalOverlayLibFactory::getOverlayLibPath($c->modalOverlayLib) .DS, |
---|
| 149 | 'pluginPath' => $this->getPluginPath(), |
---|
| 150 | 'pluginUrl' => $this->getPluginUrl() |
---|
| 151 | )); |
---|
| 152 | |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | protected function addVideoContentTemplateVars(&$tpl_var, $matches) { |
---|
| 156 | global $picture; |
---|
| 157 | // Add shadogo plugin paramters |
---|
| 158 | $tpl_var['U_PLAYER'] = $this->getOverlayLib()->getPlayerUrl(); |
---|
| 159 | // TODO: add lib configruation tab in the plugin administration console |
---|
| 160 | $tpl_var['FLASH_VARS'] = $this->getOverlayLib()->getFlashVarsTemplate(); |
---|
| 161 | |
---|
| 162 | // Add media parameters |
---|
| 163 | if (!empty($matches['path']) && !empty($matches['file']) && !empty($matches['media'])) { |
---|
| 164 | if (isset($tpl_var['NAME'])) $tpl_var['NAME'] = str_replace('_', ' ', $matches['file']); |
---|
| 165 | $tpl_var['MEDIA'] = strtolower($matches['media']); |
---|
| 166 | $filePath = ltrim($matches['path'], './'); |
---|
| 167 | $tpl_var['VIDEO_URL'] = get_absolute_root_url(false) . $filePath .'/'. $matches['file'] .'.'. $matches['media']; |
---|
| 168 | if (!empty($matches['width'])) $tpl_var['VIDEO_WIDTH'] = $matches['width']; |
---|
| 169 | if (!empty($matches['height'])) $tpl_var['VIDEO_HEIGHT'] = $matches['height']; |
---|
| 170 | } |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | public function onEndIndexThumbnails($tpl_thumbnails_var) { |
---|
| 174 | global $template, $user; |
---|
| 175 | |
---|
| 176 | $pattern = $this->getConfig()->mediaFilePattern; |
---|
| 177 | if (!empty($pattern)) { |
---|
| 178 | $favorites; |
---|
| 179 | if (!is_a_guest() and $this->getConfig()->get('favoritePicture')) { |
---|
| 180 | // Get the user favorite pictures |
---|
| 181 | $query = 'SELECT image_id AS iid FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'].';'; |
---|
| 182 | $favorites = array_from_query( $query, 'iid'); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | $nbrElements = count($tpl_thumbnails_var); |
---|
| 186 | for ($i = 0; $i < $nbrElements; $i++) { |
---|
| 187 | if (preg_match($pattern, $tpl_thumbnails_var[$i]['FILE_PATH'],$matches)) { |
---|
| 188 | $this->addVideoContentTemplateVars($tpl_thumbnails_var[$i], $matches); |
---|
| 189 | $tpl_thumbnails_var[$i]['U_OVERLAY'] = $tpl_thumbnails_var[$i]['VIDEO_URL']; |
---|
| 190 | } else { |
---|
| 191 | $tpl_thumbnails_var[$i]['U_OVERLAY'] = $tpl_thumbnails_var[$i]['FILE_PATH']; |
---|
| 192 | if ($tpl_thumbnails_var[$i]['FILE_HAS_HD'] === true) { |
---|
| 193 | $pi = pathinfo($tpl_thumbnails_var[$i]['FILE_PATH']); |
---|
| 194 | $tpl_thumbnails_var[$i]['U_HIGH'] = $pi['dirname'].'/pwg_high/'.$pi['basename']; |
---|
| 195 | } |
---|
| 196 | } |
---|
| 197 | $tpl_thumbnails_var[$i]['REL_OVERLAY'] = $this->getOverlayLib()->getDefaultLinkRelationship(); |
---|
| 198 | if (isset($favorites)) { |
---|
| 199 | $tpl_thumbnails_var[$i]['IS_FAVORITE'] = (int) in_array($tpl_thumbnails_var[$i]['ID'], $favorites); |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | $this->assignPluginTemplateVars($template); |
---|
| 204 | return $tpl_thumbnails_var; |
---|
| 205 | } |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | public function onRenderElementContent($content, $element_info) { |
---|
| 209 | global $page; |
---|
| 210 | $pattern = $this->getConfig()->mediaFilePattern; |
---|
| 211 | // Do not display video player in the slideshow |
---|
| 212 | if (!empty($pattern) && !$page['slideshow']) { |
---|
| 213 | if (preg_match($pattern, $element_info['image_url'], $matches)) { |
---|
| 214 | global $page, $template; |
---|
| 215 | $template->set_template_dir('./plugins/'. basename(dirname(__FILE__)) .'/template'); |
---|
| 216 | $template->set_filenames( |
---|
| 217 | array('default_content'=>'video_content.tpl') |
---|
| 218 | ); |
---|
| 219 | $params = array( |
---|
| 220 | 'SRC_IMG' => $element_info['image_url'], |
---|
| 221 | 'ALT_IMG' => $element_info['file'], |
---|
| 222 | 'WIDTH_IMG' => @$element_info['scaled_width'], |
---|
| 223 | 'HEIGHT_IMG' => @$element_info['scaled_height'], |
---|
| 224 | ); |
---|
| 225 | $this->addVideoContentTemplateVars($params, $matches); |
---|
| 226 | $params['REL_OVERLAY'] = $this->getOverlayLib()->getDefaultLinkRelationship(); |
---|
| 227 | $template->assign( $params ); |
---|
| 228 | return $template->parse( 'default_content', true); |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | return $content; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | public function onAppendHeader() { |
---|
| 235 | global $template; |
---|
| 236 | $css = '<link rel="stylesheet" href="'. $this->getPluginURL() .'/shadogo.css" type="text/css" media="screen" />'; |
---|
| 237 | $template->append('head_elements', $css); |
---|
| 238 | $this->getOverlayLib()->appendHeaderContent($template, 'head_elements', $this->getConfig()); |
---|
| 239 | } |
---|
| 240 | } // End class |
---|
| 241 | |
---|
| 242 | $obj = Shadogo::getInstance($plugin['id']); |
---|
| 243 | |
---|
| 244 | |
---|
| 245 | // Event admin |
---|
| 246 | add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'onAdminMenu') ); |
---|
| 247 | |
---|
| 248 | // Event site |
---|
| 249 | add_event_handler('loc_end_page_header', array(&$obj, 'onAppendHeader')); |
---|
| 250 | add_event_handler('loc_begin_picture', array(&$obj, 'onBeginPicture')); |
---|
| 251 | add_event_handler('loc_begin_index', array(&$obj, 'onBeginIndex')); |
---|
| 252 | add_event_handler('loc_end_index_thumbnails', array(&$obj, 'onEndIndexThumbnails')); |
---|
| 253 | if ($obj->getConfig()->displayMediaPlayer === true) { |
---|
| 254 | // add event handler for rendering element content EVENT_HANDLER_PRIORITY_NEUTRAL - 1 in order to be triggerd before the default handler |
---|
| 255 | add_event_handler('render_element_content', array(&$obj, 'onRenderElementContent'), EVENT_HANDLER_PRIORITY_NEUTRAL - 1, 2); |
---|
| 256 | } |
---|
| 257 | |
---|
| 258 | function shadogo_pictureprefilter($content, &$smarty) { |
---|
| 259 | $obj = get_plugin_data(Shadogo::$PLUGIN_ID); |
---|
| 260 | $c = $obj->getConfig(); |
---|
| 261 | return preg_replace($c->hdPicturePrefilterPattern, $c->hdPicturePrefilterReplacement, $content); |
---|
| 262 | } |
---|
| 263 | function shadogo_slideshowprefilter($content, &$smarty) { |
---|
| 264 | $obj = get_plugin_data(Shadogo::$PLUGIN_ID); |
---|
| 265 | $c = $obj->getConfig(); |
---|
| 266 | return preg_replace($c->slideshowPrefilterPattern, $c->slideshowPrefilterReplacement, $content); |
---|
| 267 | } |
---|
| 268 | function shadogo_closeslideshowprefilter($content, &$smarty) { |
---|
| 269 | $obj = get_plugin_data(Shadogo::$PLUGIN_ID); |
---|
| 270 | $c = $obj->getConfig(); |
---|
| 271 | return preg_replace($c->slideshowClosePattern, $c->slideshowCloseReplacement, $content); |
---|
| 272 | } |
---|
| 273 | // Prefilter for thumbnail |
---|
| 274 | function shadogo_thumbprefilter($content, &$smarty) { |
---|
| 275 | static $thumbButtonsTemplate, $thumbContentTemplate; |
---|
| 276 | $obj = get_plugin_data(Shadogo::$PLUGIN_ID); |
---|
| 277 | $c = $obj->getConfig(); |
---|
| 278 | |
---|
| 279 | if ($c->thumbInOverlay === true ) { |
---|
| 280 | |
---|
| 281 | if (empty($thumbContentTemplate)) { |
---|
| 282 | $thumbContentTemplate = file_get_contents( $obj->getPluginPath() .DS. 'template' .DS. 'thumbnail_shadogo_content.tpl' ); |
---|
| 283 | } |
---|
| 284 | // replace all occurences |
---|
| 285 | $content = str_replace($c->thumbHrefContentSearch, $thumbContentTemplate, $content); |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | if ($c->thumbMediaPlayerIcon === true || $c->thumbContentIcon === true) { |
---|
| 289 | |
---|
| 290 | if (empty($thumbButtonsTemplate)) { |
---|
| 291 | $thumbButtonsTemplate = file_get_contents( $obj->getPluginPath() .DS. 'template' .DS. 'thumbnail_shadogo_buttons.tpl' ); |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | $count = 1; // replace only the first occurence |
---|
| 295 | $content = str_replace($c->thumbButtonsTemplateSearch, $thumbButtonsTemplate, $content, $count); |
---|
| 296 | } |
---|
| 297 | return $content; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | ?> |
---|