Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Wp Music Player
- Plugin URI: http://sabdsoft.com/
- Description: This wordpress plugin displays Music File on Front End
- Version: 1.1
- License: GPL
- Author: Hiren Patel
- */
- // Define Post Details Paths and Directories
- define("MUSIC_PLAYER_FILENAME", basename(__FILE__));
- $path = $_SERVER['REQUEST_URI'];
- $path_length = strpos($path, MUSIC_PLAYER_FILENAME) + strlen(MUSIC_PLAYER_FILENAME);
- $path = substr($path, 0, strpos($path, '?')) . '?page=' . MUSIC_PLAYER_FILENAME;
- define("MP_ADMIN_PLUGIN_PATH", $path);
- if ($IS_WINDOWS) {
- $temp = str_replace(MUSIC_PLAYER_FILENAME, "", __FILE__);
- $temp = str_replace("\\", "/", $temp); //switch direction of slashes
- define("MUSIC_PLAYER_PLUGIN_PATH", $temp);
- } else {
- define("MUSIC_PLAYER_PLUGIN_PATH", str_replace(MUSIC_PLAYER_FILENAME, "", __FILE__));
- }
- if ( ! defined( 'WP_CONTENT_URL' ) )
- define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
- if ( ! defined( 'WP_CONTENT_DIR' ) )
- define( 'WP_CONTENT_DIR', ABSOLUTE_PATH . 'wp-content' );
- if ( ! defined( 'WP_PLUGIN_URL' ) )
- define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
- if ( ! defined( 'WP_PLUGIN_DIR' ) )
- define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
- // Determine whether we're in HTTPS mode or not, and change URL's accordingly.
- if(isset($_SERVER['HTTPS']) AND $_SERVER['HTTPS'] == 'on')
- {
- define('MUSIC_PLAYER_SITE_URL', str_replace('http://', 'https://', get_bloginfo('url')));
- define('MUSIC_PLAYER_BLOG_URL', str_replace('http://', 'https://', get_bloginfo('wpurl')));
- }
- else
- {
- define('MUSIC_PLAYER_SITE_URL', get_bloginfo('url'));
- define('MUSIC_PLAYER_BLOG_URL', get_bloginfo('wpurl'));
- }
- define("MUSIC_PLAYER_PLUGIN_URL", WP_PLUGIN_URL."/wp-music-player/");
- define("UPLOAD_PATH",WP_CONTENT_DIR.'/uploads/wp_music_player_songs');
- define("UPLOAD_URL",WP_CONTENT_URL.'/uploads/wp_music_player_songs');
- // Require support files.
- include_once(MUSIC_PLAYER_PLUGIN_PATH ."install.php");
- include_once(MUSIC_PLAYER_PLUGIN_PATH ."head.php");
- include_once(MUSIC_PLAYER_PLUGIN_PATH ."post.php");
- include_once(MUSIC_PLAYER_PLUGIN_PATH ."list.php");
- include_once(MUSIC_PLAYER_PLUGIN_PATH ."setting.php");
- //hook for activation and unistall
- //install
- register_activation_hook(__FILE__,'wp_music_player_install');
- //uninstall
- register_uninstall_hook(__FILE__, 'wp_music_player_Uninstall' );
- // Hook for adding admin menus
- add_action('admin_menu', 'wp_music_player_add_pages');
- // action function for above hook
- function wp_music_player_add_pages()
- {
- // Add a new submenu under Settings:
- add_options_page(__('Wp Music Player','wp_music_player'), __('Wp Music Player','wp_music_player'), 'manage_options', MUSIC_PLAYER_FILENAME, 'wp_music_player_options_page');
- }
- function wp_music_player_options_page($action=""){
- global $wpdb;
- ?>
- <div id="icon-tools" class="icon32"><br>
- </div>
- <div class="wrap">
- <h2>
- <?php _e('Song Management', 'wp_music_player'); ?>
- </h2>
- <?php
- if(!isset($_GET['action'])) $_GET['action'] = false;
- switch($_GET['action']) {
- case "new":
- wp_music_player_new();
- break;
- case "edit":
- wp_music_player_edit($_GET['editid']);
- break;
- case "setting":
- wp_music_player_setting();
- break;
- case "view":
- default:
- wp_music_player_list_page();
- break;
- }
- ?>
- </div>
- <?php
- }
- //New details
- function wp_music_player_new()
- {
- global $wpdb;
- //add edit record
- if(isset($_POST['Submit']))
- {
- // A form was added to the post. Go ahead and add or modify it in the db.
- $song['title'] = addslashes($_POST['title']);
- $song['song_name'] = addslashes($_FILES['musicfile']['name']);
- $song['composer'] = addslashes($_POST['composer']);
- //print_r($song);die;
- $error = "";
- if($_POST['title'] == "")
- $error .= "Title Cannot be blank<br>";
- if($_POST['composer'] == '')
- $error .= "Composer Cannot be blank<br>";
- if($_FILES['musicfile']['name'] == '')
- $error .= "Upload a File<br>";
- if($_FILES['musicfile']['name'] != '')
- {
- $extArray = explode('.',$_FILES['musicfile']['name']);
- $ext=$extArray[count($extArray)-1];
- if(!in_array(strtoupper($ext),array('MP3','WAVE','WAV','MP4')))
- {
- $error .= "Not valid file(File Supported MP3,Wave,mp4)<br>";
- }
- }
- if($error != "")
- {
- $_SESSION['message'] = $error;
- }
- else
- {
- $wpdb->insert($wpdb->prefix."music_player_songs", $song);
- $id=$wpdb->insert_id;
- if($_FILES['musicfile']['name']!="")
- {
- $filename=$id.".".$ext;
- $target_path = UPLOAD_PATH."/".$filename;
- move_uploaded_file($_FILES['musicfile']["tmp_name"], $target_path);
- }
- $_SESSION['message'] = "Record Inserted Successfuly";
- ?>
- <script type="text/javascript">
- <!--
- window.location = "<?=MP_ADMIN_PLUGIN_PATH?>&action=edit&editid=<?=$id?>&msg=2"
- //-->
- </script>
- <?php
- }
- }
- wp_music_player_admin_nav(); ?>
- <div class="wrap">
- <h2>
- <?php _e('Add Song'); ?>
- </h2>
- <div class="narrow">
- <?php if($_SESSION['message']){ ?>
- <div class="updated"><p><strong><?php echo $_SESSION['message'];?></strong></p></div>
- <? } ?>
- <form name="form1" method="post" action="" enctype="multipart/form-data">
- <table width="400" cellpadding="0" cellspacing="0" border="0">
- <tr>
- <td><table id="table" border="1" width="100%">
- <tbody>
- <tr>
- <td>Title</td>
- <td><input type="text" name="title" id="title" value="<?php echo $song['title']?>"/></td>
- </tr>
- <tr>
- <td>Upload File</td>
- <td><input type="file" name="musicfile" id="musicfile" value=""/></td>
- </tr>
- <tr>
- <td>Composer</td>
- <td><input type="text" name="composer" id="composer" value="<?php echo $song['composer']?>"/></td>
- </tr>
- </tbody>
- </table></td>
- </tr>
- <tr>
- <td> <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /></td>
- </tr>
- </table>
- </form>
- </div>
- </div>
- <?
- }
- //edit details
- function wp_music_player_edit($id)
- {
- global $wpdb,$_SESSION;
- //print_r($_SESSION);die;
- //unset($_SESSION['message']);
- $song_details = $wpdb->get_row( $wpdb->prepare("SELECT * FROM ".$wpdb->prefix."music_player_songs where id=".$id) );
- //add edit record
- if(isset($_POST['Submit']))
- {
- $_SESSION['message'] ="";
- //print "<pre>";print_r($song_details);die;
- $sql = "SELECT * FROM ".$wpdb->prefix."music_player_songs WHERE id= '" . $id . "';";
- $song = $wpdb->get_row($sql, ARRAY_A);
- // A form was added to the post. Go ahead and add or modify it in the db.
- $song['title'] = addslashes($_POST['title']);
- $song['song_name'] = (isset($_FILES['musicfile']['name']) && $_FILES['musicfile']['name']!='')?$_FILES['musicfile']['name']:$song_details->song_name;
- $song['composer'] = addslashes($_POST['composer']);
- $error = "";
- if($_POST['title'] == "")
- $error .= "Title Cannot be blank<br>";
- if($_POST['composer'] == '')
- $error .= "Composer Cannot be blank<br>";
- if($_FILES['musicfile']['name'] != '')
- {
- $extArray = explode('.',$_FILES['musicfile']['name']);
- $ext=$extArray[count($extArray)-1];
- if(!in_array(strtoupper($ext),array('MP3','WAVE','WAV','MP4')))
- {
- $error .= "Not valid file(File Supported MP3,Wave,mp4)<br>";
- }
- }
- if($error != "")
- {
- $_SESSION['message'] = $error;
- }
- else
- {
- if($_FILES['musicfile']['name']!="")
- {
- $filename=$id.".".$ext;
- $target_path = UPLOAD_PATH."/".$filename;
- move_uploaded_file($_FILES['musicfile']["tmp_name"], $target_path);
- }
- $wpdb->update($wpdb->prefix."music_player_songs",
- $song,
- array('id'=>$song['id'])
- );
- $_SESSION['message'] = "Record Updated Successfuly";
- }
- }
- wp_music_player_admin_nav(); ?>
- <div class="wrap">
- <h2>
- <?php _e('Add Song'); ?>
- </h2>
- <div class="narrow">
- <?php if($_SESSION['message']){ ?>
- <div class="updated"><p><strong><?php echo $_SESSION['message'];?></strong></p></div>
- <? } ?>
- <form name="form1" method="post" action="<?php echo MP_ADMIN_PLUGIN_PATH; ?>&action=edit&editid=<?php echo $id; ?>" enctype="multipart/form-data">
- <table width="400" cellpadding="0" cellspacing="0" border="0">
- <tr>
- <td><table id="table" border="1" width="100%">
- <tbody>
- <tr>
- <td>Title</td>
- <td><input type="text" name="title" id="title" value="<?php echo $song_details->title?>"/></td>
- </tr>
- <tr>
- <td>Upload File</td>
- <td><input type="file" name="musicfile" id="musicfile" value=""/><?php echo $song_details->song_name ?></td>
- </tr>
- <tr>
- <td>Composer</td>
- <td><input type="text" name="composer" id="composer" value="<?php echo $song_details->composer ?>"/></td>
- </tr>
- </tbody>
- </table></td>
- </tr>
- <tr>
- <td><input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /></td>
- </tr>
- </table>
- </form>
- </div>
- </div>
- <?
- }
- // template function
- function wp_music_player_display($content = '')
- {
- global $post, $_SERVER, $wpdb;
- $id = $post->ID;
- $file = $wpdb->get_row( $wpdb->prepare("SELECT mp.post_id, mps.*
- FROM ".$wpdb->prefix."music_player_pages mp INNER JOIN ".$wpdb->prefix."music_player_songs mps ON mp.post_music_player_id = mps.id WHERE mp.post_id =".$id) );
- if(!empty($file))
- {
- $titlestr="";
- $filenamestr="";
- $titlestr.="|".$file->title;
- $ext = substr(strchr($file->song_name,'.'),1);
- $filenamestr.="|".UPLOAD_URL."/".$file->id.".".$ext;
- $titlestr=substr($titlestr,1) ;
- $filenamestr=substr($filenamestr,1) ;
- $options= $newoptions = get_option('wp_music_player');
- //print "<pre>";print_r($options);die;
- /*?>
- <object width="200" height="100" data="<?php echo MUSIC_PLAYER_PLUGIN_URL; ?>player2.swf" type="application/x-shockwave-flash">
- <param value="transparent" name="wmode">
- <param value="<?php echo MUSIC_PLAYER_PLUGIN_URL; ?>player2.swf" name="movie">
- <param name="FlashVars" value="mp3=<?=$filenamestr?>&title=<?=$titlestr?>&autoplay=0&loop=0&showstop=1&showvolume=1&bgcolor1=696969&bgcolor2=0c0c0c&slidercolor1=cccccc&slidercolor2=999999&buttoncolor=ffffff&buttonovercolor=efea1b&sliderovercolor=efea1b&shuffle=0&width=200&height=100&textcolor=ffffff&playlistcolor=333333&playlistalpha=25&currentmp3color=ffff00&showlist=1&showplaylistnumbers=1&scrollbarcolor=ffffff&scrollbarovercolor=efea1b&loadingcolor=efea1b">
- <p>There seems to be an error with the player !</p>
- </object>
- <?*/
- $player = '<object type="application/x-shockwave-flash" data="'.MUSIC_PLAYER_PLUGIN_URL.'player2.swf" width="'.$options["width"].'" height="'.$options["height"].'">
- <param name="wmode" value="transparent" />
- <param name="movie" value="'.MUSIC_PLAYER_PLUGIN_URL.'player2.swf" />
- <param name="FlashVars" value="mp3='.$filenamestr.'&title='.$titlestr.'&autoplay='.$options["autoplay"].'&loop='.$options["loop"].'&showstop='.$options["showstop"].'&showvolume='.$options["showvolume"].'&bgcolor1='.$options["bgcolor1"].'&bgcolor2='.$options["bgcolor2"].'&slidercolor1='.$options["slidercolor1"].'&slidercolor2='.$options["slidercolor2"].'&buttoncolor='.$options["buttonovercolor"].'&buttonovercolor='.$options["hvclr"].'&sliderovercolor='.$options["sliderovercolor"].'&shuffle='.$options["shuffle"].'&width='.$options["width"].'&height='.$options["height"].'&textcolor='.$options["textcolor"].'&playlistcolor='.$options["playlistcolor"].'&playlistalpha='.$options["playlistalpha"].'&currentmp3color='.$options["currentmp3color"].'&showlist='.$options["showlist"].'&showplaylistnumbers='.$options["showplaylistnumbers"].'&scrollbarcolor='.$options["scrollbarcolor"].'&scrollbarovercolor='.$options["scrollbarovercolor"].'&loadingcolor='.$options["loadingcolor"].'" />
- </object>';
- }
- else
- {
- $player="There is no audio file regarding this post";
- }
- $content = $content .$player;
- return($content);
- }
- add_filter('the_content', 'wp_music_player_display');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment