jessiehannah

Untitled

Sep 1st, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.69 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Wp Music Player
  4. Plugin URI: http://sabdsoft.com/
  5. Description: This wordpress plugin displays Music File on Front End
  6. Version: 1.1
  7. License: GPL
  8. Author: Hiren Patel
  9. */
  10. // Define Post Details Paths and Directories
  11. define("MUSIC_PLAYER_FILENAME", basename(__FILE__));
  12. $path = $_SERVER['REQUEST_URI'];
  13. $path_length = strpos($path, MUSIC_PLAYER_FILENAME) + strlen(MUSIC_PLAYER_FILENAME);
  14.  
  15. $path = substr($path, 0, strpos($path, '?')) . '?page=' . MUSIC_PLAYER_FILENAME;
  16.  
  17. define("MP_ADMIN_PLUGIN_PATH", $path);
  18.  
  19.  
  20. if ($IS_WINDOWS) {
  21. $temp = str_replace(MUSIC_PLAYER_FILENAME, "", __FILE__);
  22. $temp = str_replace("\\", "/", $temp); //switch direction of slashes
  23. define("MUSIC_PLAYER_PLUGIN_PATH", $temp);
  24. } else {
  25. define("MUSIC_PLAYER_PLUGIN_PATH", str_replace(MUSIC_PLAYER_FILENAME, "", __FILE__));
  26. }
  27.  
  28.  
  29. if ( ! defined( 'WP_CONTENT_URL' ) )
  30. define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
  31. if ( ! defined( 'WP_CONTENT_DIR' ) )
  32. define( 'WP_CONTENT_DIR', ABSOLUTE_PATH . 'wp-content' );
  33. if ( ! defined( 'WP_PLUGIN_URL' ) )
  34. define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
  35. if ( ! defined( 'WP_PLUGIN_DIR' ) )
  36. define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
  37.  
  38. // Determine whether we're in HTTPS mode or not, and change URL's accordingly.
  39. if(isset($_SERVER['HTTPS']) AND $_SERVER['HTTPS'] == 'on')
  40. {
  41. define('MUSIC_PLAYER_SITE_URL', str_replace('http://', 'https://', get_bloginfo('url')));
  42. define('MUSIC_PLAYER_BLOG_URL', str_replace('http://', 'https://', get_bloginfo('wpurl')));
  43. }
  44. else
  45. {
  46. define('MUSIC_PLAYER_SITE_URL', get_bloginfo('url'));
  47. define('MUSIC_PLAYER_BLOG_URL', get_bloginfo('wpurl'));
  48. }
  49. define("MUSIC_PLAYER_PLUGIN_URL", WP_PLUGIN_URL."/wp-music-player/");
  50. define("UPLOAD_PATH",WP_CONTENT_DIR.'/uploads/wp_music_player_songs');
  51. define("UPLOAD_URL",WP_CONTENT_URL.'/uploads/wp_music_player_songs');
  52. // Require support files.
  53. include_once(MUSIC_PLAYER_PLUGIN_PATH ."install.php");
  54. include_once(MUSIC_PLAYER_PLUGIN_PATH ."head.php");
  55. include_once(MUSIC_PLAYER_PLUGIN_PATH ."post.php");
  56. include_once(MUSIC_PLAYER_PLUGIN_PATH ."list.php");
  57. include_once(MUSIC_PLAYER_PLUGIN_PATH ."setting.php");
  58.  
  59.  
  60. //hook for activation and unistall
  61. //install
  62. register_activation_hook(__FILE__,'wp_music_player_install');
  63. //uninstall
  64. register_uninstall_hook(__FILE__, 'wp_music_player_Uninstall' );
  65.  
  66. // Hook for adding admin menus
  67. add_action('admin_menu', 'wp_music_player_add_pages');
  68.  
  69. // action function for above hook
  70. function wp_music_player_add_pages()
  71. {
  72. // Add a new submenu under Settings:
  73. 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');
  74.  
  75. }
  76.  
  77.  
  78. function wp_music_player_options_page($action=""){
  79. global $wpdb;
  80. ?>
  81.  
  82. <div id="icon-tools" class="icon32"><br>
  83. </div>
  84. <div class="wrap">
  85. <h2>
  86. <?php _e('Song Management', 'wp_music_player'); ?>
  87. </h2>
  88. <?php
  89. if(!isset($_GET['action'])) $_GET['action'] = false;
  90. switch($_GET['action']) {
  91. case "new":
  92. wp_music_player_new();
  93. break;
  94. case "edit":
  95. wp_music_player_edit($_GET['editid']);
  96. break;
  97. case "setting":
  98. wp_music_player_setting();
  99. break;
  100. case "view":
  101. default:
  102. wp_music_player_list_page();
  103. break;
  104.  
  105. }
  106. ?>
  107. </div>
  108. <?php
  109.  
  110. }
  111. //New details
  112. function wp_music_player_new()
  113. {
  114. global $wpdb;
  115.  
  116. //add edit record
  117. if(isset($_POST['Submit']))
  118. {
  119. // A form was added to the post. Go ahead and add or modify it in the db.
  120. $song['title'] = addslashes($_POST['title']);
  121. $song['song_name'] = addslashes($_FILES['musicfile']['name']);
  122. $song['composer'] = addslashes($_POST['composer']);
  123. //print_r($song);die;
  124. $error = "";
  125. if($_POST['title'] == "")
  126. $error .= "Title Cannot be blank<br>";
  127.  
  128. if($_POST['composer'] == '')
  129. $error .= "Composer Cannot be blank<br>";
  130.  
  131. if($_FILES['musicfile']['name'] == '')
  132. $error .= "Upload a File<br>";
  133.  
  134. if($_FILES['musicfile']['name'] != '')
  135. {
  136. $extArray = explode('.',$_FILES['musicfile']['name']);
  137. $ext=$extArray[count($extArray)-1];
  138. if(!in_array(strtoupper($ext),array('MP3','WAVE','WAV','MP4')))
  139. {
  140. $error .= "Not valid file(File Supported MP3,Wave,mp4)<br>";
  141. }
  142. }
  143. if($error != "")
  144. {
  145. $_SESSION['message'] = $error;
  146. }
  147. else
  148. {
  149. $wpdb->insert($wpdb->prefix."music_player_songs", $song);
  150. $id=$wpdb->insert_id;
  151. if($_FILES['musicfile']['name']!="")
  152. {
  153. $filename=$id.".".$ext;
  154. $target_path = UPLOAD_PATH."/".$filename;
  155. move_uploaded_file($_FILES['musicfile']["tmp_name"], $target_path);
  156.  
  157. }
  158. $_SESSION['message'] = "Record Inserted Successfuly";
  159. ?>
  160. <script type="text/javascript">
  161. <!--
  162. window.location = "<?=MP_ADMIN_PLUGIN_PATH?>&action=edit&editid=<?=$id?>&msg=2"
  163. //-->
  164. </script>
  165. <?php
  166. }
  167. }
  168. wp_music_player_admin_nav(); ?>
  169. <div class="wrap">
  170. <h2>
  171. <?php _e('Add Song'); ?>
  172. </h2>
  173. <div class="narrow">
  174. <?php if($_SESSION['message']){ ?>
  175. <div class="updated"><p><strong><?php echo $_SESSION['message'];?></strong></p></div>
  176. <? } ?>
  177. <form name="form1" method="post" action="" enctype="multipart/form-data">
  178. <table width="400" cellpadding="0" cellspacing="0" border="0">
  179. <tr>
  180. <td><table id="table" border="1" width="100%">
  181. <tbody>
  182. <tr>
  183. <td>Title</td>
  184. <td><input type="text" name="title" id="title" value="<?php echo $song['title']?>"/></td>
  185. </tr>
  186. <tr>
  187. <td>Upload File</td>
  188. <td><input type="file" name="musicfile" id="musicfile" value=""/></td>
  189. </tr>
  190. <tr>
  191. <td>Composer</td>
  192. <td><input type="text" name="composer" id="composer" value="<?php echo $song['composer']?>"/></td>
  193. </tr>
  194.  
  195. </tbody>
  196. </table></td>
  197. </tr>
  198. <tr>
  199. <td> <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /></td>
  200. </tr>
  201. </table>
  202. </form>
  203. </div>
  204. </div>
  205. <?
  206. }
  207. //edit details
  208. function wp_music_player_edit($id)
  209. {
  210. global $wpdb,$_SESSION;
  211. //print_r($_SESSION);die;
  212. //unset($_SESSION['message']);
  213. $song_details = $wpdb->get_row( $wpdb->prepare("SELECT * FROM ".$wpdb->prefix."music_player_songs where id=".$id) );
  214.  
  215. //add edit record
  216. if(isset($_POST['Submit']))
  217. {
  218. $_SESSION['message'] ="";
  219. //print "<pre>";print_r($song_details);die;
  220. $sql = "SELECT * FROM ".$wpdb->prefix."music_player_songs WHERE id= '" . $id . "';";
  221.  
  222. $song = $wpdb->get_row($sql, ARRAY_A);
  223.  
  224. // A form was added to the post. Go ahead and add or modify it in the db.
  225. $song['title'] = addslashes($_POST['title']);
  226. $song['song_name'] = (isset($_FILES['musicfile']['name']) && $_FILES['musicfile']['name']!='')?$_FILES['musicfile']['name']:$song_details->song_name;
  227. $song['composer'] = addslashes($_POST['composer']);
  228.  
  229. $error = "";
  230. if($_POST['title'] == "")
  231. $error .= "Title Cannot be blank<br>";
  232.  
  233. if($_POST['composer'] == '')
  234. $error .= "Composer Cannot be blank<br>";
  235.  
  236. if($_FILES['musicfile']['name'] != '')
  237. {
  238. $extArray = explode('.',$_FILES['musicfile']['name']);
  239. $ext=$extArray[count($extArray)-1];
  240. if(!in_array(strtoupper($ext),array('MP3','WAVE','WAV','MP4')))
  241. {
  242. $error .= "Not valid file(File Supported MP3,Wave,mp4)<br>";
  243. }
  244. }
  245. if($error != "")
  246. {
  247. $_SESSION['message'] = $error;
  248. }
  249. else
  250. {
  251. if($_FILES['musicfile']['name']!="")
  252. {
  253. $filename=$id.".".$ext;
  254. $target_path = UPLOAD_PATH."/".$filename;
  255. move_uploaded_file($_FILES['musicfile']["tmp_name"], $target_path);
  256.  
  257. }
  258. $wpdb->update($wpdb->prefix."music_player_songs",
  259. $song,
  260. array('id'=>$song['id'])
  261. );
  262. $_SESSION['message'] = "Record Updated Successfuly";
  263. }
  264. }
  265.  
  266. wp_music_player_admin_nav(); ?>
  267. <div class="wrap">
  268. <h2>
  269. <?php _e('Add Song'); ?>
  270. </h2>
  271. <div class="narrow">
  272. <?php if($_SESSION['message']){ ?>
  273. <div class="updated"><p><strong><?php echo $_SESSION['message'];?></strong></p></div>
  274. <? } ?>
  275. <form name="form1" method="post" action="<?php echo MP_ADMIN_PLUGIN_PATH; ?>&action=edit&editid=<?php echo $id; ?>" enctype="multipart/form-data">
  276. <table width="400" cellpadding="0" cellspacing="0" border="0">
  277. <tr>
  278. <td><table id="table" border="1" width="100%">
  279. <tbody>
  280. <tr>
  281. <td>Title</td>
  282. <td><input type="text" name="title" id="title" value="<?php echo $song_details->title?>"/></td>
  283. </tr>
  284. <tr>
  285. <td>Upload File</td>
  286. <td><input type="file" name="musicfile" id="musicfile" value=""/><?php echo $song_details->song_name ?></td>
  287. </tr>
  288. <tr>
  289. <td>Composer</td>
  290. <td><input type="text" name="composer" id="composer" value="<?php echo $song_details->composer ?>"/></td>
  291. </tr>
  292. </tbody>
  293. </table></td>
  294. </tr>
  295. <tr>
  296. <td><input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /></td>
  297. </tr>
  298. </table>
  299. </form>
  300. </div>
  301. </div>
  302. <?
  303. }
  304. // template function
  305. function wp_music_player_display($content = '')
  306. {
  307. global $post, $_SERVER, $wpdb;
  308. $id = $post->ID;
  309.  
  310. $file = $wpdb->get_row( $wpdb->prepare("SELECT mp.post_id, mps.*
  311. 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) );
  312. if(!empty($file))
  313. {
  314. $titlestr="";
  315. $filenamestr="";
  316. $titlestr.="|".$file->title;
  317. $ext = substr(strchr($file->song_name,'.'),1);
  318. $filenamestr.="|".UPLOAD_URL."/".$file->id.".".$ext;
  319.  
  320. $titlestr=substr($titlestr,1) ;
  321. $filenamestr=substr($filenamestr,1) ;
  322.  
  323. $options= $newoptions = get_option('wp_music_player');
  324. //print "<pre>";print_r($options);die;
  325. /*?>
  326. <object width="200" height="100" data="<?php echo MUSIC_PLAYER_PLUGIN_URL; ?>player2.swf" type="application/x-shockwave-flash">
  327. <param value="transparent" name="wmode">
  328. <param value="<?php echo MUSIC_PLAYER_PLUGIN_URL; ?>player2.swf" name="movie">
  329. <param name="FlashVars" value="mp3=<?=$filenamestr?>&amp;title=<?=$titlestr?>&amp;autoplay=0&amp;loop=0&amp;showstop=1&amp;showvolume=1&amp;bgcolor1=696969&amp;bgcolor2=0c0c0c&amp;slidercolor1=cccccc&amp;slidercolor2=999999&amp;buttoncolor=ffffff&amp;buttonovercolor=efea1b&amp;sliderovercolor=efea1b&amp;shuffle=0&amp;width=200&amp;height=100&amp;textcolor=ffffff&amp;playlistcolor=333333&amp;playlistalpha=25&amp;currentmp3color=ffff00&amp;showlist=1&amp;showplaylistnumbers=1&amp;scrollbarcolor=ffffff&amp;scrollbarovercolor=efea1b&amp;loadingcolor=efea1b">
  330. <p>There seems to be an error with the player !</p>
  331. </object>
  332. <?*/
  333. $player = '<object type="application/x-shockwave-flash" data="'.MUSIC_PLAYER_PLUGIN_URL.'player2.swf" width="'.$options["width"].'" height="'.$options["height"].'">
  334. <param name="wmode" value="transparent" />
  335. <param name="movie" value="'.MUSIC_PLAYER_PLUGIN_URL.'player2.swf" />
  336. <param name="FlashVars" value="mp3='.$filenamestr.'&amp;title='.$titlestr.'&amp;autoplay='.$options["autoplay"].'&amp;loop='.$options["loop"].'&amp;showstop='.$options["showstop"].'&amp;showvolume='.$options["showvolume"].'&amp;bgcolor1='.$options["bgcolor1"].'&amp;bgcolor2='.$options["bgcolor2"].'&amp;slidercolor1='.$options["slidercolor1"].'&amp;slidercolor2='.$options["slidercolor2"].'&amp;buttoncolor='.$options["buttonovercolor"].'&amp;buttonovercolor='.$options["hvclr"].'&amp;sliderovercolor='.$options["sliderovercolor"].'&amp;shuffle='.$options["shuffle"].'&amp;width='.$options["width"].'&amp;height='.$options["height"].'&amp;textcolor='.$options["textcolor"].'&amp;playlistcolor='.$options["playlistcolor"].'&amp;playlistalpha='.$options["playlistalpha"].'&amp;currentmp3color='.$options["currentmp3color"].'&amp;showlist='.$options["showlist"].'&amp;showplaylistnumbers='.$options["showplaylistnumbers"].'&amp;scrollbarcolor='.$options["scrollbarcolor"].'&amp;scrollbarovercolor='.$options["scrollbarovercolor"].'&amp;loadingcolor='.$options["loadingcolor"].'" />
  337. </object>';
  338. }
  339. else
  340. {
  341. $player="There is no audio file regarding this post";
  342. }
  343. $content = $content .$player;
  344. return($content);
  345. }
  346.  
  347. add_filter('the_content', 'wp_music_player_display');
  348.  
  349. ?>
Advertisement
Add Comment
Please, Sign In to add comment