관리-도구
편집 파일: flvplayer.php
<?php /* Plugin Name: FlvPlayer Version: 0.4.2 Plugin URI: http://weblog.theentirety.com/2005/07/13/flvplayer/ Description: A plugin that displays progressive streaming videos in .flv format and progressive streaming .mp3 audio files. Author: Aaron Martlage Author URI: http://www.theentirety.com Change log: 0.4.2 -- Fixed: file:// inserts by editor for includes 0.4.1 -- Fixed: Problem with clean install and array for exclude files Fixed: mod_rewrite regular expression to allow for passed query variables 0.4.0 -- Added: Friendly URI support and added details on the options page on how to implement it Changed: All global variables switched to constants 0.3.0 -- Removed: paginate.php and abstract.php since they were remnants from the first port and causing problems for some installs Added: AsySound to play .mp3 files (http://redalt.com/downloads/ - under Flash Filter Plus and AsySound Added: Jeroen Wijering's FlvPlayer (http://www.jeroenwijering.com/?item=Flash+Video+Player) as yet another alternative to play the .flv files Changed: Moved CSS from this document to an included php file that could be edited independent of the options screen Added: Mp3 selection drop down to the WP admin console Added: JW's FlvPlayer option to the WP admin console Removed: Any references to code-bits from paginate or abstract 0.2.0 -- Added: Flowplayer (http://flowplayer.sourceforge.net/flow.html) as an alternative .flv player - Thanks macewan! (http://www.macewan.org/) Added: WordPress admin option to choose the .flv player to display on the site 0.1.2 -- Fixed: Internet Explorer wasn't loading the player because of a bad directory call. Changed label of "Video Redirect" in WP Admin console Options > FlvPlayer to "WordPress Page Address" 0.1.1 -- Added template file to zip so that new pages can be assigned FlvPlayer template 0.1 -- First version of FlvPlayer plugin Ability to choose to display of movie links as list, in drop down or not at all Includes javascript function hooked into WordPress API to launch window from any link Pagination in list mode not operating correctly for WordPress absolute paths Copyright (c) 2005 Released under the GPL license http://www.gnu.org/licenses/gpl.txt This file is part of WordPress. WordPress is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* Plugin Constants - DO NOT CHANGE */ session_start(); define('PLUGIN_DIR', '/wp-content/plugins/flvplayer/'); // This is the plugin directory. define('FLVPLAYER_CSS', (get_option('flvplayer__css') != '' ? get_option('flvplayer__css') : require('flvplayercss.php'))); define('VIDEO_REDIRECT', (get_option('flvplayer__video_redirect') != '' ? get_option('flvplayer__video_redirect') : '/videos/')); // This is the alias wordpress creates for your page. define('VIDEO_REPOSITORY', (get_option('flvplayer__video_repository') != '' ? get_option('flvplayer__video_repository') : 'http://videos.yourwebsite.com/')); // This is the repository of all your .flv files. define('VIDEO_REPOSITORY_FILE', (get_option('flvplayer__video_repository_file') != '' ? get_option('flvplayer__video_repository_file') : '/home/www/videos/')); // This is the server path to the repository of all your .flv files. define('ITEMS_PER_PAGE', (get_option('flvplayer__items_per_page') != '' ? get_option('flvplayer__items_per_page') : 1000)); // Still working on properly implementing the paging for wordpress. define('EXCLUDE', (get_option('flvplayer__exclude') != '' ? get_option('flvplayer__exclude') : '.,..,readme.txt,text,__player.swf,__player_proxus.swf,__player_flowplayer.swf,__flowtracker.swc,__flowplayer.swc,__flashdetection.swf,__noflash.php,cgi-bin,error_log')); // If you have other files in your video repository, be sure to add them to the exclusion list so they don't show up in your list of videos. define('DISPLAY_TYPE', (get_option('flvplayer__display_type') != '' ? get_option('flvplayer__display_type') : 'list')); // To display movies as a drop down list, set value to 'dropdown'. To display movies in a paginated list, set value to 'list'. To not display any other movies, set value to 'none'. define('VIDEOPLAYER_TYPE', (get_option('flvplayer__videoplayer_type') != '' ? get_option('flvplayer__videoplayer_type') : '__player_proxus')); // Select which type of player to display define('MP3PLAYER_TYPE', (get_option('flvplayer__mp3player_type') != '' ? get_option('flvplayer__mp3player_type') : '__player_jwmp3')); // Select which type of player to display define('FRIENDLY_URI', (get_option('flvplayer__friendly_uri') != '' ? get_option('flvplayer__friendly_uri') : 'false')); // True passes the video to play as a friendly URI without query variables, false passes the video as url=xxx /* Main functions to build various video components*/ function flvplayer_show_videos() { $url = get_url(); $ext = strstr($url[0], '.'); echo '<span id="flvplayer">'; if ($_SESSION['flashok'] == 'true') { if ($ext == '.flv') { show_video(); } elseif ($ext == '.mp3') { show_audio(); } show_video_options(); } else { if ($url[1] == 'noflash') { show_no_flash_message(); } else { if ($url[1] == 'flashok') { $_SESSION['flashok'] = 'true'; if ($ext == '.flv') { show_video(); } elseif ($ext == '.mp3') { show_audio(); } show_video_options(); } else { show_flash_check(); } } } echo '</span>'; } function dir_count() { $num = 0 ; $handle = opendir(VIDEO_REPOSITORY_FILE); $exclude = explode(chr(13) . chr(10), EXCLUDE); if (sizeof($exclude) <= 1) $exclude = explode(',', EXCLUDE); while ($file = readdir($handle)) { if (in_array($file, EXCLUDE)) continue; else $num++; } closedir($handle); return $num; } function show_flash_check() { $url = get_url(); $pass_url = 'url=' . $url[0] . '__flashok'; $returnstring = ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" width="80" height="80"> <param name="movie" value="' . VIDEO_REPOSITORY . '__flashdetection.swf?flashContentURL=' . VIDEO_REDIRECT . '?' . $pass_url . '&altContentURL=' .VIDEO_REDIRECT. '?url=__noflash&contentVersion=7&contentMajorRevision=0&contentMinorRevision=0&allowFlashAutoInstall=false" /> <param name="quality" value="low" /> <embed src="' . VIDEO_REPOSITORY . '__flashdetection.swf?flashContentURL=' . VIDEO_REDIRECT . '?' . $pass_url . '&altContentURL=' .VIDEO_REDIRECT. '?url=__noflash&contentVersion=7&contentMajorRevision=0&contentMinorRevision=0&allowFlashAutoInstall=false" quality="low" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="80" height="80" /> </object> '; echo $returnstring; } function get_url() { if (@$_POST["url"]) $url = $_POST["url"]; else if (@$_GET["url"]) $url = $_GET["url"]; else $url = ''; $url = explode('__',$url); return $url; } function show_video() { $url = get_url(); $url = $url[0]; echo '<span class="nowwatching">Now Watching </span>'; $ext = strrchr($url, ".php"); $filename = substr($url, 0, -strlen($ext)); echo '<span class="nowwatchingfilename">' . $filename . '</span><br />'; echo '<span class="playerspace">'; if (VIDEOPLAYER_TYPE == '__player_jwflv') { echo ' <object type="application/x-shockwave-flash" width="400" height="300" wmode="transparent" data="' . VIDEO_REPOSITORY . VIDEOPLAYER_TYPE . '.swf?file=' . $url . '">'; echo ' <param name="movie" value="' . VIDEO_REPOSITORY . VIDEOPLAYER_TYPE . '.swf?file=' . $url . '" />'; echo ' <param name="wmode" value="transparent" />'; echo ' </object>'; } else { echo ' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="320" height="240" id="' . VIDEOPLAYER_TYPE . '" align="middle">'; echo ' <param name="allowFlashAutoInstall" value="true">'; echo ' <param name="movie" value="' . VIDEO_REPOSITORY . VIDEOPLAYER_TYPE . '.swf" />'; echo ' <param name="allowScriptAccess" value="sameDomain" />'; echo ' <param name="quality" value="high" />'; echo ' <param name="bgcolor" value="#ffffff" />'; if (VIDEOPLAYER_TYPE == '__player_proxus') { echo ' <param name="Flashvars" value="url=' .$url . '">'; echo ' <embed src="' . VIDEO_REPOSITORY . VIDEOPLAYER_TYPE . '.swf" swLiveConnect="true" Flashvars="url=' .$url . '" quality="high" bgcolor="#ffffff" width="320" height="240" name="' . VIDEOPLAYER_TYPE . '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'; } if (VIDEOPLAYER_TYPE == '__player_flowplayer') { echo ' <param name="Flashvars" value="videoFile=' .$url . '">'; echo ' <embed src="' . VIDEO_REPOSITORY . VIDEOPLAYER_TYPE . '.swf" swLiveConnect="true" Flashvars="videoFile=' .$url . '" quality="high" bgcolor="#ffffff" width="320" height="240" name="' . VIDEOPLAYER_TYPE . '" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'; } echo ' </object>'; } echo '</span>'; echo '<a href="javascript:playFlvVideo(\'' .$filename . '\')" class="newwindowlink">Open video in new window</a>'; } function show_audio() { $url = get_url(); $url = $url[0]; echo '<span class="nowwatching">Now Listening To </span>'; $ext = strrchr($url, ".php"); $filename = substr($url, 0, -strlen($ext)); echo '<span class="nowwatchingfilename">' . $filename . '</span><br />'; echo '<span class="playerspace">'; if (MP3PLAYER_TYPE == '__player_jwmp3') { echo ' <object type="application/x-shockwave-flash" data="' . VIDEO_REPOSITORY . MP3PLAYER_TYPE . '.swf" width="280" height="280" wmode="transparent">'; echo ' <param name="movie" value="' . VIDEO_REPOSITORY . MP3PLAYER_TYPE . '.swf" />'; echo ' </object>'; } if (MP3PLAYER_TYPE == '__player_asysound') { echo ' <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="50">'; echo ' <param name="movie" value="' . VIDEO_REPOSITORY . MP3PLAYER_TYPE . '.swf">'; echo ' <param name="quality" value="high">'; echo ' <embed src="' . VIDEO_REPOSITORY . MP3PLAYER_TYPE . '.swf?' . VIDEO_REPOSITORY . $url . '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="50">'; echo ' </embed>'; echo ' </object>'; } echo '</span>'; } function show_video_options() { $handle = opendir(VIDEO_REPOSITORY_FILE); $exclude = explode(chr(13) . chr(10), EXCLUDE); if (sizeof($exclude) <= 1) $exclude = explode(',', EXCLUDE); while ($file = readdir($handle)) { $ext = strrchr($file, ".flv"); $filename = substr($file, 0, -strlen($ext)); if (in_array($file, $exclude)) { continue; } else { $result[] = ($file); } } closedir($handle); if (@DISPLAY_TYPE != 'none') { if (DISPLAY_TYPE == 'dropdown') { echo '<form name="flvplayer_selectVideo" action="' . VIDEO_REDIRECT . '" method="get">'; echo ' <select name="url" class="dropdown">'; echo ' <option>Select a video...</option>'; foreach ($result as $option) { echo ' <option value="' . $option . '" >' . substr($option, 0, -strlen($ext)) . '</option>'; } echo ' </select>'; echo ' <input type="submit" value="Play >"/>'; echo '</form>'; return; } if (DISPLAY_TYPE == 'list') { echo '<ol>'; foreach ($result as $option) { if (FRIENDLY_URI == 'true') { $temp_option = explode('.',$option); echo '<li><a href="' . VIDEO_REDIRECT . $temp_option[1] . '/' . $temp_option[0] . '/">' . substr($option, 0, -strlen($ext)) . '</a></li>'; } else { echo '<li><a href="' . VIDEO_REDIRECT . '?url=' . $option . '">' . substr($option, 0, -strlen($ext)) . '</a></li>'; } } echo '</ol>'; } } } function flvplayer_js() { switch (VIDEOPLAYER_TYPE) { case '__player_proxus': $sendvars = 'url'; break; case '__player_flowplayer': $sendvars = 'videoFile'; break; case '__player_jwflv': $sendvars = 'file'; break; } $returnstring = ' <script language="JavaScript"> <!-- function playFlvVideo(targeturl) { window.open("' . VIDEO_REPOSITORY . '/__flashdetection.swf?flashContentURL=' . VIDEOPLAYER_TYPE . '.swf?' . $sendvars . '=" + targeturl + ".flv&altContentURL=' .VIDEO_REPOSITORY. '__noflash.php&contentVersion=7&contentMajorRevision=0&contentMinorRevision=0&allowFlashAutoInstall=false","", "scrollbars=no,resizable=yes,width=350,height=300") } //--> </script>'; echo $returnstring; } function flvplayer_css() { $returnstring = ' <style type="text/css">' . FLVPLAYER_CSS . ' </style>'; echo $returnstring; } function show_no_flash_message() { echo require('noflash.php'); } function show_flvplayer_options() { $returnstring = ''; if (isset($_POST['info_update'])) { foreach ($_POST as $key => $value) { if (update_option($key, $value) != 1) $returnstring .= $key . ' failed to update!<br />'; } $returnstring .= '<div class="updated"><p><strong>Options saved.</strong></p></div>'; } $returnstring .= ' <div class=wrap> <form method="post"> <h2>FlvPlayer Options</h2> <table width="100%" cellspacing="2" cellpadding="5" class="editform"> <tr valign="top"> <th width="33%" scope="row">WordPress Page Address:</th> <td><input name="flvplayer__video_redirect" type="text" id="flvplayer__video_redirect" value="' . (get_option('flvplayer__video_redirect') != '' ? get_option('flvplayer__video_redirect') : VIDEO_REDIRECT) . '" size="40" /> <br /> After the flash detection or upon selecting a different video, this is the absolute or relative URI to redirect the page to. </td> </tr> <tr valign="top"> <th scope="row">Video Repository (URI):</th> <td><input name="flvplayer__video_repository" type="text" id="flvplayer__video_repository" value="' . (get_option('flvplayer__video_repository') != '' ? get_option('flvplayer__video_repository') : VIDEO_REPOSITORY) . '" size="40" /> <br /> This is the absolute URI where all your .flv files are stored. </td> </tr> <tr valign="top"> <th scope="row">Video Repository (on server):</th> <td><input name="flvplayer__video_repository_file" type="text" id="flvplayer__video_repository_file" value="' . (get_option('flvplayer__video_repository_file') != '' ? get_option('flvplayer__video_repository_file') : VIDEO_REPOSITORY_file) . '" size="40" /> <br /> This is the physical path on the server where the .flv files are stored. </td> </tr> <tr valign="top"> <th scope="row">Use Frindly URI:</th> <td>'; $frindly_uri_var = (get_option('flvplayer__friendly_uri') != '' ? get_option('flvplayer__friendly_uri') : 'false'); $returnstring .= ' <input type="radio" value="true" name="flvplayer__friendly_uri" id="flvplayer__friendly_uri"' . ($frindly_uri_var == 'true' ? ' checked="checked"' : '') . ' />True <input type="radio" value="false" name="flvplayer__friendly_uri" id="flvplayer__friendly_uri"' . ($frindly_uri_var == 'false' ? ' checked="checked"' : '') . ' />False<br /> If you elect to use friendly URIs, you must have <code>mod_rewrite</code> installed on Apache and add:<br /> <code>RewriteRule ^(videos)/(flv|mp3)/(.*)/ /$1/?url=$3.$2 [QSA,L]<br /> RewriteRule ^(videos)/(flv|mp3)/(.*)/^\?(.*) /$1/?url=$3.$2&$4 [QSA,L]</code><br /> to your .htaccess file replacing<br /> <code>videos</code><br /> with the text only from your WordPress Page Address field above. </td> </tr> <tr valign="top"> <th scope="row">Items per page:</th> <td><input name="flvplayer__items_per_page" type="text" id="flvplayer__items_per_page" value="' . (get_option('flvplayer__items_per_page') != '' ? get_option('flvplayer__items_per_page') : ITEMS_PER_PAGE) . '" size="10" disabled="disabled"/> Currently disabled for this release</td> </tr> <tr valign="top"> <th scope="row">Files to exclude: </th> <td><textarea name="flvplayer__exclude" id="flvplayer__exclude" rows="10" cols="30" class="code" >' . (get_option('flvplayer__exclude') != '' ? get_option('flvplayer__exclude') : EXCLUDE) . '</textarea> <br /> When the plugin reads your video directory for the .flv files, it needs to know which files you don\'t want it to play. This player will play .flv, .mp3, .avi. All items should be placed on separate lines with no spaces. </td> </tr> <tr valign="top"> <th scope="row">Display list type:</th> <td>'; $display_type_var = (get_option('flvplayer__display_type') != '' ? get_option('flvplayer__display_type') : DISPLAY_TYPE); $returnstring .= ' <select name="flvplayer__display_type" id="flvplayer__display_type"> <option value="list"' . ($display_type_var == 'list' ? ' selected="selected"' : '') . '>List</option> <option value="dropdown"' . ($display_type_var == 'dropdown' ? ' selected="selected"' : '') . '>Dropdown</option> <option value="none"' . ($display_type_var == 'none' ? ' selected="selected"' : '') . '>None</option> </select> </td> </tr> <tr valign="top"> <th scope="row">Video Player:</th> <td>'; $videoplayer_type_var = (get_option('flvplayer__videoplayer_type') != '' ? get_option('flvplayer__videoplayer_type') : VIDEOPLAYER_TYPE); $returnstring .= ' <select name="flvplayer__videoplayer_type" id="flvplayer__videoplayer_type"> <option value="__player_proxus"' . ($videoplayer_type_var == '__player_proxus' ? ' selected="selected"' : '') . '>Proxus</option> <option value="__player_flowplayer"' . ($videoplayer_type_var == '__player_flowplayer' ? ' selected="selected"' : '') . '>FlowPlayer</option> <option value="__player_jwflv"' . ($videoplayer_type_var == '__player_jwflv' ? ' selected="selected"' : '') . '>Jeroen Wijering FlvPlayer</option> </select> </td> </tr> <tr valign="top"> <th scope="row">Mp3 Player:</th> <td>'; $mp3player_type_var = (get_option('flvplayer__mp3player_type') != '' ? get_option('flvplayer__mp3player_type') : MP3PLAYER_TYPE); $returnstring .= ' <select name="flvplayer__mp3player_type" id="flvplayer__mp3player_type"> <option value="__player_asysound"' . ($mp3player_type_var == '__player_asysound' ? ' selected="selected"' : '') . '>AsySound</option> '; // <option value="__player_jwmp3"' . (MP3PLAYER_TYPE_var == '__player_jwmp3' ? ' selected="selected"' : '') . '>Jeroen Wijering Mp3Player</option> $returnstring .= ' </select> </td> </tr> <tr valign="top"> <th scope="row">CSS:</th> <td><textarea name="flvplayer__css" id="flvplayer__css" rows="20" cols="50" class="code" >' . (get_option('flvplayer__css') != '' ? get_option('flvplayer__css') : FLVPLAYER_CSS) . '</textarea> <br /> </td> </tr> </table> <div class="submit"> <input type="submit" name="info_update" value="Update Options »" /> </div> </form> </div>'; echo $returnstring; } function mt_add_pages() { add_options_page('FlvPlayer Options', 'FlvPlayer', 8, __FILE__, 'show_flvplayer_options'); } add_option('flvplayer__css', FLVPLAYER_CSS, 'FlvPlayer Plugin Variable - Stores the redirect path for the videos', 'yes'); add_option('flvplayer__video_redirect', VIDEO_REDIRECT, 'FlvPlayer Plugin Variable - Stores the redirect path for the videos', 'yes'); add_option('flvplayer__video_repository', VIDEO_REPOSITORY, 'FlvPlayer Plugin Variable - Stores the repository (URI) for the videos', 'yes'); add_option('flvplayer__video_repository_file', VIDEO_REPOSITORY_file, 'FlvPlayer Plugin Variable - Stores the repository server path for the videos', 'yes'); add_option('flvplayer__items_per_page', ITEMS_PER_PAGE, 'FlvPlayer Plugin Variable - Stores the number of videos to display per page', 'yes'); add_option('flvplayer__exclude', EXCLUDE, 'FlvPlayer Plugin Variable - Stores the list of files to exclude from the list of videos', 'yes'); add_option('flvplayer__display_type', DISPLAY_TYPE, 'FlvPlayer Plugin Variable - Stores the style for displaying the list of videos', 'yes'); add_option('flvplayer__videoplayer_type', VIDEOPLAYER_TYPE, 'FlvPlayer Plugin Variable - Stores the player to display the videos in', 'yes'); add_option('flvplayer__mp3player_type', MP3PLAYER_TYPE, 'Mp3 Plugin Variable - Stores the player to play the audio files in', 'yes'); add_option('flvplayer__friendly_uri', FRIENDLY_URI, 'True or false to pass the video as a search engine friendly URI', 'yes'); add_action('wp_head', 'flvplayer_js'); add_action('wp_head', 'flvplayer_css'); add_action('admin_menu', 'mt_add_pages'); ?>