PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/flvplayer/flvplayer.php

https://github.com/Amydrion/Unsupported
PHP | 327 lines | 224 code | 20 blank | 83 comment | 43 complexity | 3ca3a893c5c94a320e451862057d7ece MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * flvplayer -- plugin support for the flvplayer flash video player v4.5.
  4. *
  5. * Note: 1.1 now incorporates the former separate flv_playlist plugin to show the content of an media album with .flv/.mp4/.mp3 movie/audio files as a playlist or as separate players with flv player.
  6. * Note:</strong> No <em>FLVPlayer</em> player files are included with this plugin due to licensing considerations. Please download these files from the <a href="http://www.longtailvideo.com/players/jw-flv-player/">Longtail Video</a> site. Extract the files and place the files "player*.swf" and "swobjects.js" in the <code>zp-core/plugins/flvplayer/flvplayer</code> folder.
  7. *
  8. * IMPORTANT: Flash players do not support external albums!
  9. *
  10. * @author Malte M端ller (acrylian), Stephen Billard (sbillard)
  11. * @package plugins
  12. */
  13. $plugin_description = sprintf(gettext('Enable <strong>FLV player 4.x</strong> to handle multimedia files.').'<p class="notebox">'.gettext('<strong>No <em>FLVPlayer</em> player files are included with this plugin due to licensing considerations.</strong> Please download these files from the <a href="http://www.longtailvideo.com/players/jw-flv-player/">Longtail Video</a> site. Extract the files "player*.swf" and "swobjects.js" into <code>/%s/flvplayer/</code>. <br /><strong>IMPORTANT:</strong> Only one multimedia player plugin can be enabled at the time. The class-video plugin must be enabled.').'</p>',USER_PLUGIN_FOLDER);
  14. $plugin_author = "Malte M端ller (acrylian), Stephen Billard (sbillard)";
  15. $plugin_version = '1.3.1';
  16. $plugin_disable = (getOption('album_folder_class') === 'external')?gettext('Flash players do not support <em>External Albums</em>.'):false;
  17. if ($plugin_disable) {
  18. setOption('zp_plugin_flvplayer',0);
  19. } else {
  20. $option_interface = new flvplayer();
  21. $_zp_flash_player = $option_interface; // claim to be the flash player.
  22. if (version_compare(ZENPHOTO_VERSION,'1.3.2') < 0) {
  23. ob_start();
  24. flvplayerJS();
  25. $str = ob_get_contents();
  26. ob_end_clean();
  27. addPluginScript($str);
  28. } else {
  29. zp_register_filter('theme_head', 'flvplayerJS');
  30. }
  31. }
  32. function flvplayerJS() {
  33. ?>
  34. <script type="text/javascript" src="<?php echo WEBPATH.'/'.USER_PLUGIN_FOLDER; ?>/flvplayer/swfobject.js"></script>
  35. <?php
  36. }
  37. define ('FLV_PLAYER_MP3_HEIGHT', 20);
  38. // load the script needed
  39. $curdir = getcwd();
  40. chdir(SERVERPATH."/".USER_PLUGIN_FOLDER.'/flvplayer');
  41. $_playerlist = safe_glob('*.swf');
  42. if (count($_playerlist) > 0) {
  43. $_flv_player = array_shift($_playerlist);
  44. } else {
  45. $_flv_player = '';
  46. }
  47. chdir($curdir);
  48. /**
  49. * Plugin option handling class
  50. *
  51. */
  52. class flvplayer {
  53. function flvplayer() {
  54. setOptionDefault('flv_player_width', '320');
  55. setOptionDefault('flv_player_height', '240');
  56. setOptionDefault('flv_player_backcolor', '#FFFFFF');
  57. setOptionDefault('flv_player_frontcolor', '#000000');
  58. setOptionDefault('flv_player_lightcolor', '#000000');
  59. setOptionDefault('flv_player_screencolor', '#000000');
  60. setOptionDefault('flv_player_autostart', '');
  61. setOptionDefault('flv_player_buffer','0');
  62. setOptionDefault('flv_player_controlbar','over');
  63. setOptionDefault('flv_player_stretching','uniform');
  64. //setOptionDefault('flv_player_ignoresize_for_mp3', 'true');
  65. // flv_playlist options
  66. setOptionDefault('flvplaylist_width', '600');
  67. setOptionDefault('flvplaylist_height', '240');
  68. setOptionDefault('flvplaylist_size', '240');
  69. setOptionDefault('flvplaylist_position', 'right');
  70. setOptionDefault('flvplaylist_repeat', 'list');
  71. }
  72. function getOptionsSupported() {
  73. global $_flv_player;
  74. if (empty($_flv_player)) {
  75. return array(gettext('No FLV Player') => array('key' => 'flvplayer', 'type' => OPTION_TYPE_CUSTOM,
  76. 'desc' => gettext('No <em>FLVPlayer</em> player files are included with this plugin due to licensing considerations. Please download these files from the <a href="http://www.longtailvideo.com/players/jw-flv-player/">Longtail Video</a> site. Extract the files and place the files "player*.swf" and "swobjects.js" in a folder named <code>flvplayer</code> in the global plugins folder.')));
  77. }
  78. $result = array(gettext('flv player width') => array('key' => 'flv_player_width', 'type' => OPTION_TYPE_TEXTBOX,
  79. 'desc' => gettext("Player width (ignored for <em>mp3</em> files.)")),
  80. gettext('flv player height') => array('key' => 'flv_player_height', 'type' => OPTION_TYPE_TEXTBOX,
  81. 'desc' => gettext("Player height (ignored for .<em>mp3</em> files if there is no preview image available.)")),
  82. gettext('Autostart') => array('key' => 'flv_player_autostart', 'type' => OPTION_TYPE_CHECKBOX,
  83. 'desc' => gettext("Should the video start automatically. Yes if selected.")),
  84. gettext('BufferSize') => array('key' => 'flv_player_buffer', 'type' => OPTION_TYPE_TEXTBOX,
  85. 'desc' => /*xgettext:no-php-format*/ gettext("Size of the buffer in % before the video starts.")),
  86. gettext('Controlbar position') => array('key' => 'flv_player_controlbar', 'type' => OPTION_TYPE_SELECTOR,
  87. 'selections' => array(gettext('Bottom')=>"bottom", gettext('Over')=>"over", gettext('None')=>"none"),
  88. 'desc' => gettext("The position of the controlbar.")),
  89. gettext('Playlist position') => array('key' => 'flvplaylist_position', 'type' => OPTION_TYPE_SELECTOR,
  90. 'selections' => array(gettext('Bottom')=>"bottom", gettext('Over')=>"over", gettext('Right')=>"right",gettext('None')=>"none"),
  91. 'desc' => gettext("Position of the playlist (only if using the special <code>flvplaylist()</code> function).")),
  92. gettext('Playlist size') => array('key' => 'flvplaylist_size', 'type' => OPTION_TYPE_TEXTBOX,
  93. 'desc' => gettext("When <em>playlist</em> is set to <em>below</em> this refers to the height, when <em>right</em> this refers to the width of the playlist (only if using the special <code>flvplaylist()</code> function).")),
  94. gettext('Playlist repeat') => array('key' => 'flvplaylist_repeat','type' => OPTION_TYPE_SELECTOR,
  95. 'selections' => array(gettext('List')=>"list", gettext('Always')=>"always", gettext('Single')=>"single"),
  96. 'desc' => gettext("set to list to play the entire playlist once, to always to continously play the song/video/playlist and to single to continue repeating the selected file in a playlist. (only if using the special <code>flvplaylist()</code> function).")),
  97. gettext('flv player width for playlist') => array('key' => 'flvplaylist_width', 'type' => OPTION_TYPE_TEXTBOX,
  98. 'desc' => gettext("Player width for use with the playlist (ignored for <em>mp3</em> files.)")),
  99. gettext('flv player height for playlist') => array('key' => 'flvplaylist_height', 'type' => OPTION_TYPE_TEXTBOX,
  100. 'desc' => gettext("Player height for use with the playlist (ignored for .<em>mp3</em> files if there is no preview image available.)")),
  101. gettext('Backcolor') => array('key' => 'flv_player_backcolor', 'type' => OPTION_TYPE_COLOR_PICKER,
  102. 'desc' => gettext("Backgroundcolor of the controls, in HEX format.")),
  103. gettext('Frontcolor') => array('key' => 'flv_player_frontcolor', 'type' => OPTION_TYPE_COLOR_PICKER,
  104. 'desc' => gettext("Text &amp; buttons color of the controls, in HEX format. ")),
  105. gettext('Lightcolor') => array('key' => 'flv_player_lightcolor', 'type' => OPTION_TYPE_COLOR_PICKER,
  106. 'desc' => gettext("Rollover color of the controls, in HEX format.")),
  107. gettext('Screencolor') => array('key' => 'flv_player_screencolor', 'type' => OPTION_TYPE_COLOR_PICKER,
  108. 'desc' => gettext("Color of the display area, in HEX format.")),
  109. gettext('Stretching') => array('key' => 'flv_player_stretching', 'type' => OPTION_TYPE_SELECTOR,
  110. 'selections' => array(gettext('Exactfit')=>"exactfit", gettext('Uniform')=>"uniform", gettext('Fill')=>"fill", gettext('None')=>"none"),
  111. 'desc' => gettext("Defines how to resize images in the display. Can be none (no stretching), exactfit (disproportionate), uniform (stretch with black borders) or fill (uniform, but completely fill the display).")),
  112. );
  113. return $result;
  114. }
  115. /**
  116. * handles any custom options
  117. *
  118. * @param string $option
  119. * @param mixed $currentValue
  120. */
  121. function handleOption($option, $currentValue) {
  122. echo gettext('FLV Player support files missing.');
  123. }
  124. /**
  125. * Prints the JS configuration of flv player
  126. *
  127. * @param string $moviepath the direct path of a movie (within the slideshow), if empty (within albums) the ZenPhoto function getUnprotectedImageURL() is used
  128. * @param string $imagetitle the title of the movie to be passed to the player for display (within slideshow), if empty (within albums) the function getImageTitle() is used
  129. * @param string $count unique text for when there are multiple player items on a page
  130. */
  131. function getPlayerConfig($moviepath='',$imagetitle='',$count ='') {
  132. global $_zp_current_image, $_zp_current_album, $_flv_player;
  133. if(empty($moviepath)) {
  134. $moviepath = getUnprotectedImageURL();
  135. $ext = strtolower(strrchr(getUnprotectedImageURL(), "."));
  136. } else {
  137. $ext = strtolower(strrchr($moviepath, "."));
  138. }
  139. if(empty($imagetitle)) {
  140. $imagetitle = getImageTitle();
  141. }
  142. if(!empty($count)) {
  143. $count = "-".$count;
  144. }
  145. $imgextensions = array(".jpg",".jpeg",".gif",".png");
  146. if(is_null($_zp_current_image)) {
  147. $albumfolder = $moviepath;
  148. $filename = $imagetitle;
  149. $videoThumb = '';
  150. } else {
  151. $album = $_zp_current_image->getAlbum();
  152. $albumfolder = $album->name;
  153. $filename = $_zp_current_image->filename;
  154. $videoThumb = $_zp_current_image->objectsThumb;
  155. if (!empty($videoThumb)) {
  156. $videoThumb = getAlbumFolder(WEBPATH).$albumfolder.'/'.$videoThumb;
  157. }
  158. }
  159. $output = '';
  160. $output .= '<p id="player'.$count.'">'.gettext('The flv player is not installed. Please install or activate the flv player plugin.').'</p>
  161. <script type="text/javascript">'."\n\n";
  162. if($ext === ".mp3" AND !isset($videoThumb)) {
  163. $output .= 'var so = new SWFObject("'.WEBPATH."/".USER_PLUGIN_FOLDER.'/flvplayer/'.$_flv_player.'","player'.$count.'","'.getOption('flv_player_width').'","'.FLV_PLAYER_MP3_HEIGHT.'",7);'."\n";
  164. } else {
  165. $output .= 'var so = new SWFObject("'.WEBPATH."/".USER_PLUGIN_FOLDER.'/flvplayer/'.$_flv_player.'","player'.$count.'","'.getOption('flv_player_width').'","'.getOption('flv_player_height').'","7");'."\n";
  166. }
  167. $output .= 'so.addVariable("file","' . $moviepath . '&amp;title=' . strip_tags($imagetitle) . '");'."\n";
  168. if (!empty($videoThumb)) {
  169. $output .= 'so.addVariable("image","' . $videoThumb . '");'."\n";
  170. }
  171. $output .= 'so.addVariable("backcolor","'.getOptionColor('flv_player_backcolor').'");'."\n";
  172. $output .= 'so.addVariable("frontcolor","'.getOptionColor('flv_player_frontcolor').'");'."\n";
  173. $output .= 'so.addVariable("lightcolor","'.getOptionColor('flv_player_lightcolor').'");'."\n";
  174. $output .= 'so.addVariable("screencolor","'.getOptionColor('flv_player_screencolor').'");'."\n";
  175. $output .= 'so.addVariable("autostart",' . (getOption('flv_player_autostart') ? 'true' : 'false') . ');'."\n";
  176. $output .= 'so.addVariable("stretching","'.getOption('flv_player_stretching').'");'."\n";
  177. $output .= 'so.addVariable("bufferlength",'.getOption('flv_player_buffer').');'."\n";
  178. $output .= 'so.addVariable("controlbar","'.getOption('flv_player_controlbar').'");'."\n";
  179. $output .= 'so.addParam("allowfullscreen",true);'."\n";
  180. $output .= 'so.write("player'.$count.'");'."\n";
  181. $output .= "\n</script>\n";
  182. return $output;
  183. }
  184. /**
  185. * outputs the player configuration HTML
  186. *
  187. * @param string $moviepath the direct path of a movie (within the slideshow), if empty (within albums) the ZenPhoto function getUnprotectedImageURL() is used
  188. * @param string $imagetitle the title of the movie to be passed to the player for display (within slideshow), if empty (within albums) the function getImageTitle() is used
  189. * @param string $count unique text for when there are multiple player items on a page
  190. */
  191. function printPlayerConfig($moviepath='',$imagetitle='',$count ='') {
  192. echo $this->getPlayerConfig($moviepath,$imagetitle,$count);
  193. }
  194. /**
  195. * Returns the height of the player
  196. * @param object $image the image for which the width is requested
  197. *
  198. * @return int
  199. */
  200. function getVideoWidth($image=NULL) {
  201. return getOption('flv_player_width');
  202. }
  203. /**
  204. * Returns the width of the player
  205. * @param object $image the image for which the height is requested
  206. *
  207. * @return int
  208. */
  209. function getVideoHeigth($image=NULL) {
  210. if (!is_null($image) && strtolower(strrchr($image->filename, ".") == '.mp3')) {
  211. return FLV_PLAYER_MP3_HEIGHT;
  212. }
  213. return getOption('flv_player_height');
  214. }
  215. }
  216. /**
  217. * To show the content of an media album with .flv/.mp4/.mp3 movie/audio files only as a playlist or as separate players with flv player
  218. * NOTE: The flv player plugin needs to be installed (This plugin currently internally uses FLV player 3 because of FLV player 4 Api changes!)
  219. *
  220. * The playlist is meant to replace the 'next_image()' loop on a theme's album.php.
  221. * It can be used with a special 'album theme' that can be assigned to media albums with with .flv/.mp4/.mp3s
  222. * movie/audio files only. See the examples below
  223. * You can either show a 'one player window' playlist or show all items as separate players paginated
  224. * (set in the settings for thumbs per page) on one page (like on a audio or podcast blog).
  225. *
  226. * If there is no preview image for a mp3 file existing only the player control bar is shown.
  227. *
  228. * The two modes:
  229. * a) 'playlist'
  230. * Replace the entire 'next_image()' loop on album.php with this:
  231. * <?php flvPlaylist("playlist"); ?>
  232. *
  233. * It uses a xspf file found in 'zp-core/flvplayer/flvplayer/playlist.php' for the playlist that you also can modify. You can also use other XML formats for a playlist See http://developer.longtailvideo.com/trac/wiki/FlashFormats
  234. *
  235. * b) 'players'
  236. * Modify the 'next_image()' loop on album.php like this:
  237. * <?php
  238. * while (next_image():
  239. * printImageTitle();
  240. * flvPlaylist("players");
  241. * endwhile;
  242. * ?>
  243. * Of course you can add further functions to b) like title, description, date etc., too.
  244. *
  245. * @param string $option the mode to use "playlist" or "players"
  246. */
  247. function flvPlaylist($option='') {
  248. global $_zp_current_album, $_zp_current_image, $_flv_player,$_zp_flash_player;
  249. if(checkAlbumPassword($_zp_current_album->getFolder(), $hint)) {
  250. if($option === "players") {
  251. $moviepath = getUnprotectedImageURL();
  252. $ext = strtolower(strrchr(getUnprotectedImageURL(), "."));
  253. }
  254. $imagetitle = getImageTitle();
  255. }
  256. $albumid = getAlbumID();
  257. switch($option) {
  258. case "playlist":
  259. if(getNumImages() != 0) {
  260. ?>
  261. <div id="flvplaylist"><?php echo gettext("The flv player is not installed. Please install or activate the flv player plugin."); ?></div>
  262. <script type="text/javascript">
  263. var so = new SWFObject('<?php echo WEBPATH.'/'.USER_PLUGIN_FOLDER; ?>/flvplayer/<?php echo $_flv_player?>','flvplaylist','<?php echo getOption('flvplaylist_width'); ?>','<?php echo getOption('flvplaylist_height'); ?>','8');
  264. so.addParam('allowfullscreen','true');
  265. so.addVariable('stretching','<?php echo getOption('flv_player_stretching'); ?>');
  266. so.addVariable('playlist', '<?php echo getOption('flvplaylist_position'); ?>');
  267. so.addVariable('playlistsize','<?php echo getOption('flvplaylist_size'); ?>');
  268. so.addVariable('repeat','<?php echo getOption('flvplaylist_repeat'); ?>');
  269. so.addVariable('backcolor','<?php echo getOptionColor('flv_player_backcolor'); ?>');
  270. so.addVariable('frontcolor','<?php echo getOptionColor('flv_player_frontcolor'); ?>');
  271. so.addVariable('lightcolor','<?php echo getOptionColor('flv_player_lightcolor'); ?>');
  272. so.addVariable('screencolor','<?php echo getOptionColor('flv_player_screencolor'); ?>');
  273. so.addVariable('file','<?php echo WEBPATH."/".USER_PLUGIN_FOLDER; ?>/flvplayer/playlist.php?albumid=<?php echo $albumid; ?>');
  274. so.addVariable('javascriptid','jstest');
  275. so.addVariable('enablejs','true');
  276. so.write('flvplaylist');
  277. </script>
  278. <?php }
  279. break;
  280. case "players":
  281. if (($ext == ".flv") || ($ext == ".mp3") || ($ext == ".mp4")) {
  282. if (is_null($_zp_flash_player)) {
  283. echo "<img src='" . WEBPATH . '/' . ZENFOLDER . "'/images/err-noflashplayer.gif' alt='".gettext('The flv player is not installed. Please install or activate the flv player plugin.')."' />";
  284. } else {
  285. $_zp_flash_player->printPlayerConfig(getFullImageURL(),$_zp_current_image->getTitle(),$_zp_current_image->get("id"));
  286. }
  287. }
  288. break;
  289. }
  290. }
  291. /**
  292. * Returns the "color" setting of the option after converting it to connical form
  293. *
  294. * @param string $option
  295. * @return string
  296. */
  297. function getOptionColor($option) {
  298. $color = getOption($option);
  299. if (substr($color,0,1) == '#') {
  300. $color = '0x'.strtoupper(substr($color,1));
  301. }
  302. return $color;
  303. }
  304. ?>