loadConfig(); set_plugin_data(self::$PLUGIN_ID, self::$_instance); return self::$_instance; } public function getPluginPath() { if ( !isset($this->_pluginPath) ) $this->_pluginPath = dirname(__FILE__); return $this->_pluginPath; } public function getPluginURL() { if ( !isset($this->_pluginURL) ) $this->_pluginURL = get_root_url() .'plugins/'. basename(dirname(__FILE__)); return $this->_pluginURL; } public function &getConfig() { global $conf; if (isset($this->_config)) return $this->_config; // the config is initialized in DB during the plugin installation if (isset( $conf[ShadogoConfig::$CONFIG_NAME])) { $this->_config = new ShadogoConfig(); return $this->_config; } // !! Not possible if the plugin is well installed $this->_config = $this->getDefaultConfig(); return $this->_config; } public function getDefaultConfig() { $c = ShadogoConfig::createDefaultConfiguration(); return new ShadogoConfig($c); } // // Modal overlay lib // public function getOverlayLib($libName = null) { if (empty($libName)) { $libName = $this->getConfig()->modalOverlayLib; } if ( !empty( $this->_overlayLibs[$libName] )) { return $this->_overlayLibs[$libName]; } $this->_overlayLibs[$libName] = ModalOverlayLibFactory::createModalOverlayLib($libName); return $this->_overlayLibs[$libName]; } public function getInstalledOverlayLibs() { return ModalOverlayLibFactory::getInstalledOverlayLibs(); } // // Admin // public function onAdminMenu($menu) { array_push($menu, array( 'NAME' => 'Shadogo', 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/shadogo_admin.php') ) ); return $menu; } // // Site Event Management // public function onBeginPicture() { global $template; if ($this->getConfig()->hdPictureInOverlay === true) { $template->set_prefilter('default_content', 'shadogo_pictureprefilter'); } if ($this->getConfig()->slideshowInOverlay === true) { $template->set_prefilter('picture', 'shadogo_slideshowprefilter'); $template->set_prefilter('slideshow', 'shadogo_closeslideshowprefilter'); } } public function onBeginIndex() { global $template; $test = $this->getConfig(); if ($this->getConfig()->thumbInOverlay === true) { $template->set_prefilter('index_thumbnails', 'shadogo_thumbprefilter'); } if ($this->getConfig()->slideshowInOverlay === true) { $template->set_prefilter('index', 'shadogo_slideshowprefilter'); $template->set_prefilter('slideshow', 'shadogo_closeslideshowprefilter'); } } protected function assignPluginTemplateVars($template) { $c = $this->getConfig(); $template->assign(ShadogoConfig::$CONFIG_NAME, array( 'thumbMediaPlayerIcon' => $c->thumbMediaPlayerIcon, 'thumbContentIcon' => $c->thumbContentIcon, 'thumbContentLabel' => $c->thumbContentLabel, 'thumbContentInOverlay' => $c->thumbContentInOverlay, 'overlayLibName' => $c->modalOverlayLib, 'overlayLibPath' => ModalOverlayLibFactory::getOverlayLibPath($c->modalOverlayLib) .DS, 'pluginPath' => $this->getPluginPath(), 'pluginUrl' => $this->getPluginUrl() )); } protected function addVideoContentTemplateVars(&$tpl_var, $matches) { global $picture; // Add shadogo plugin paramters $tpl_var['U_PLAYER'] = $this->getOverlayLib()->getPlayerUrl(); // TODO: add lib configruation tab in the plugin administration console $tpl_var['FLASH_VARS'] = $this->getOverlayLib()->getFlashVarsTemplate(); // Add media parameters if (!empty($matches['path']) && !empty($matches['file']) && !empty($matches['media'])) { if (isset($tpl_var['NAME'])) $tpl_var['NAME'] = str_replace('_', ' ', $matches['file']); $tpl_var['MEDIA'] = strtolower($matches['media']); $filePath = ltrim($matches['path'], './'); $tpl_var['VIDEO_URL'] = get_absolute_root_url(false) . $filePath .'/'. $matches['file'] .'.'. $matches['media']; if (!empty($matches['width'])) $tpl_var['VIDEO_WIDTH'] = $matches['width']; if (!empty($matches['height'])) $tpl_var['VIDEO_HEIGHT'] = $matches['height']; } } public function onEndIndexThumbnails($tpl_thumbnails_var) { global $template, $user; $pattern = $this->getConfig()->mediaFilePattern; if (!empty($pattern)) { $favorites; if (!is_a_guest() and $this->getConfig()->get('favoritePicture')) { // Get the user favorite pictures $query = 'SELECT image_id AS iid FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'].';'; $favorites = array_from_query( $query, 'iid'); } $nbrElements = count($tpl_thumbnails_var); for ($i = 0; $i < $nbrElements; $i++) { if (preg_match($pattern, $tpl_thumbnails_var[$i]['FILE_PATH'],$matches)) { $this->addVideoContentTemplateVars($tpl_thumbnails_var[$i], $matches); $tpl_thumbnails_var[$i]['U_OVERLAY'] = $tpl_thumbnails_var[$i]['VIDEO_URL']; } else { $tpl_thumbnails_var[$i]['U_OVERLAY'] = $tpl_thumbnails_var[$i]['FILE_PATH']; if ($tpl_thumbnails_var[$i]['FILE_HAS_HD'] === true) { $pi = pathinfo($tpl_thumbnails_var[$i]['FILE_PATH']); $tpl_thumbnails_var[$i]['U_HIGH'] = $pi['dirname'].'/pwg_high/'.$pi['basename']; } } $tpl_thumbnails_var[$i]['REL_OVERLAY'] = $this->getOverlayLib()->getDefaultLinkRelationship(); if (isset($favorites)) { $tpl_thumbnails_var[$i]['IS_FAVORITE'] = (int) in_array($tpl_thumbnails_var[$i]['ID'], $favorites); } } $this->assignPluginTemplateVars($template); return $tpl_thumbnails_var; } } public function onRenderElementContent($content, $element_info) { global $page; $pattern = $this->getConfig()->mediaFilePattern; // Do not display video player in the slideshow if (!empty($pattern) && !$page['slideshow']) { if (preg_match($pattern, $element_info['image_url'], $matches)) { global $page, $template; $template->set_template_dir('./plugins/'. basename(dirname(__FILE__)) .'/template'); $template->set_filenames( array('default_content'=>'video_content.tpl') ); $params = array( 'SRC_IMG' => $element_info['image_url'], 'ALT_IMG' => $element_info['file'], 'WIDTH_IMG' => @$element_info['scaled_width'], 'HEIGHT_IMG' => @$element_info['scaled_height'], ); $this->addVideoContentTemplateVars($params, $matches); $params['REL_OVERLAY'] = $this->getOverlayLib()->getDefaultLinkRelationship(); $template->assign( $params ); return $template->parse( 'default_content', true); } } return $content; } public function onAppendHeader() { global $template; $css = ''; $template->append('head_elements', $css); $this->getOverlayLib()->appendHeaderContent($template, 'head_elements', $this->getConfig()); } } // End class $obj = Shadogo::getInstance($plugin['id']); // Event admin add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'onAdminMenu') ); // Event site add_event_handler('loc_end_page_header', array(&$obj, 'onAppendHeader')); add_event_handler('loc_begin_picture', array(&$obj, 'onBeginPicture')); add_event_handler('loc_begin_index', array(&$obj, 'onBeginIndex')); add_event_handler('loc_end_index_thumbnails', array(&$obj, 'onEndIndexThumbnails')); if ($obj->getConfig()->displayMediaPlayer === true) { // add event handler for rendering element content EVENT_HANDLER_PRIORITY_NEUTRAL - 1 in order to be triggerd before the default handler add_event_handler('render_element_content', array(&$obj, 'onRenderElementContent'), EVENT_HANDLER_PRIORITY_NEUTRAL - 1, 2); } function shadogo_pictureprefilter($content, &$smarty) { $obj = get_plugin_data(Shadogo::$PLUGIN_ID); $c = $obj->getConfig(); return preg_replace($c->hdPicturePrefilterPattern, $c->hdPicturePrefilterReplacement, $content); } function shadogo_slideshowprefilter($content, &$smarty) { $obj = get_plugin_data(Shadogo::$PLUGIN_ID); $c = $obj->getConfig(); return preg_replace($c->slideshowPrefilterPattern, $c->slideshowPrefilterReplacement, $content); } function shadogo_closeslideshowprefilter($content, &$smarty) { $obj = get_plugin_data(Shadogo::$PLUGIN_ID); $c = $obj->getConfig(); return preg_replace($c->slideshowClosePattern, $c->slideshowCloseReplacement, $content); } // Prefilter for thumbnail function shadogo_thumbprefilter($content, &$smarty) { static $thumbButtonsTemplate, $thumbContentTemplate; $obj = get_plugin_data(Shadogo::$PLUGIN_ID); $c = $obj->getConfig(); if ($c->thumbInOverlay === true ) { if (empty($thumbContentTemplate)) { $thumbContentTemplate = file_get_contents( $obj->getPluginPath() .DS. 'template' .DS. 'thumbnail_shadogo_content.tpl' ); } // replace all occurences $content = str_replace($c->thumbHrefContentSearch, $thumbContentTemplate, $content); } if ($c->thumbMediaPlayerIcon === true || $c->thumbContentIcon === true) { if (empty($thumbButtonsTemplate)) { $thumbButtonsTemplate = file_get_contents( $obj->getPluginPath() .DS. 'template' .DS. 'thumbnail_shadogo_buttons.tpl' ); } $count = 1; // replace only the first occurence $content = str_replace($c->thumbButtonsTemplateSearch, $thumbButtonsTemplate, $content, $count); } return $content; } ?>