Jump to content

Writing to XML File


jagger

Recommended Posts

Hi,

 

I am using a custom music player module for Drupal. I have not been able to get it to work. I found out that the problem lies in the write_xml function. It creates an xml playlist that the flash player loads. The link to the uploaded music file is passed as:

 

url=\"sites/default/files" .$album_song->fmp_song_name. "\" />"

 

 

The problem I believe is in the concatenation. The XML playlist shows the url as only "sites/default/files" when it should show something like "sites/default/files/wow.mp3"

 

 

I am not experienced with PHP and am just trying to get this module to work.

Link to comment
Share on other sites

We would need to see more code to know if the concatenation is right or not.

 

add this to see if the filename is being filled in properly.

echo 'Song: '.$album_song->fmp_song_name;

 

If you get

Song:   

then the var is not right, if you get

Song: name_of_song.mp3, then it is filled in correctly.

 

Nate

 

Link to comment
Share on other sites

Here is the entire function.

 

function write_xml(){
$sql="SELECT fmp_albums.fmp_album_name FROM fmp_albums";	
$to_write="<?xml version=\"1.0\" ?>\n\t<songs>";	
$result = db_query($sql);	
while($dept = db_fetch_object($result)){
	$to_write .= "\n\n\t\t<album name=\"".$dept->fmp_album_name."\">";	
	$song_sql="select fmp_songs.fmp_song_name, fmp_songs.fmp_song_title from fmp_songs where fmp_songs.fmp_album_id=(select fmp_albums.fmp_album_id from fmp_albums where fmp_albums.fmp_album_name='".$dept->fmp_album_name."')";	
	//$song_sql="select * from fmp_songs,fmp_albums where fmp_songs.fmp_album_id=fmp_albums.fmp_album_id";
	$result_song = db_query($song_sql);	
while($album_song = db_fetch_object($result_song)) {
	$to_write .="\n\t\t\t<song display=\"".$album_song->fmp_song_title."\" 
      url=\"sites/default/files/" .$album_song->fmp_song_name. "\"  />";
      echo 'Song: '.$album_song->fmp_song_name;
	}	
	$to_write .= "\n\t\t</album>";
}	
$to_write .= "\n\n\t</songs>";	
echo $to_write;	
$myFile = "modules/music_player/songlist.xml";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $to_write);
fclose($fh);
}

Link to comment
Share on other sites

Looks to me like this

url=\"sites/default/files" .$album_song->fmp_song_name. "\" />"

 

Needs to be this instead

url=$ablum_song->fmp_song_name />

 

I am too tired to try and decipher the concatenation in that code as it is MESSY, so you can do that, but the result is giving you the path and filename, so you don't need to include that in the url= bit.

 

If that is exactly what came from the database, then it is being added on insert. I would start there.

Link to comment
Share on other sites

Hi,

 

Thanks for your help. The code is very messy. I am trying my best to deal with a module that I had someone else build and is not working.

 

Very weird things are happening. When I tried your suggestion, it gave me a php error unexpected T_Constant.

 

When I add another song, it adds the url path from the first song to the url path of the second song.

 

This keeps getting stranger and stranger.

Link to comment
Share on other sites

It is still trying to serve the directory. When I tried your suggestion it gave me a PHP error.

 

Parse error: parse error, unexpected T_constant_ENCAPSED_STRING, expecting ';' ','

If anyone is interested, I can send you the entire file.

 

 

 

Thanks

Link to comment
Share on other sites

Ok, I went through your code and have hopefully fixed any errors. You will notice that I have change a majority of the " " to ' '.

 

It is more just personal opinion, but I find it easier to use ' ' most of the time when dealing with strings. Then when you come across a variable, you just concatenate it. I do this because it is easier to read the concatenated strings rather than trying to use \ to escape " when dealing with HTML code.

 

SQL Queries are the exception. I use "" around those because inside them, the WHERE pieces typically need to be surrounded by ' ' for the query to work. By surrounding them with " ", the single quotes inside are parsed as vars with ' around them instead of literal strings.

 

I also UPPERCASED all sql commands... e.g. SELECT FROM WHERE GROUP... i find it easier to read the queries that way.

 

Again, this is more just personal preference, but I have found these to be the easiest ways to read the code and to write it.

 

<?php
function write_xml()
{
   $sql="SELECT fmp_albums.fmp_album_name FROM fmp_albums";  

   $to_write = '<?xml version="1.0" ?>'."\n\t".'<songs>';   
/* when I post this, the beginning ' gets stripped off the beginning of the xml block.. 
so make sure it is there when you put it back in your script */   

   $result = db_query($sql);   

   while($dept = db_fetch_object($result))
{
      $to_write .= "\n\n\t\t".'<album name="'.$dept->fmp_album_name.'">';  

      $song_sql="SELECT fmp_songs.fmp_song_name, fmp_songs.fmp_song_title FROM fmp_songs WHERE fmp_songs.fmp_album_id='(SELECT fmp_albums.fmp_album_id FROM fmp_albums WHERE fmp_albums.fmp_album_name='$dept->fmp_album_name')'";   
      //$song_sql="select * from fmp_songs,fmp_albums where fmp_songs.fmp_album_id=fmp_albums.fmp_album_id";
      $result_song = db_query($song_sql);  

	while($album_song = db_fetch_object($result_song)) 
	{
		$to_write .="\n\t\t\t".'<song display="'.$album_song->fmp_song_title.'" url="'.$album_song->fmp_song_name.'"  />';
	}   

      $to_write .= "\n\t\t".'</album>';
   }   

   $to_write .= "\n\n\t".'</songs>';   

echo $to_write;
  /*
   $myFile = 'modules/music_player/songlist.xml';
   $fh = fopen($myFile, 'w') or die("can't open file");
   fwrite($fh, $to_write);
   fclose($fh);
*/
}

?>

 

I commented the write part out so that you can get the xml correct before writing to the file..... I also changed the url=.... part like I had said before. Try that and see what you get. If there are still issues, post the XML code here as well so I can see what it getting generated.

 

Nate

Link to comment
Share on other sites

<?xml version="1.0" ?>
<songs>

	<album name="sss">
		<song display="sdfdf" url=""  />
		<song display="aasdasd" url=""  />
		<song display="asdadssd" url=""  />
		<song display="nnsdfsdf" url=""  />
		<song display="aaaa" url=""  />
	</album>

</songs>

 

 

Here is the XML code. The url is blank

Link to comment
Share on other sites

Before the path was coming back. Now the path is blank. I have been looking for where it is defined and the only thing I can find is

 

function fmp_manager_delete($did = 0) {
$sql="select s.fmp_song_name FROM {fmp_songs s} WHERE fmp_song_id = $did";
$result = db_query($sql);
while($l = db_fetch_object($result)) {
	$location=$l->fmp_song_name;
}	
$file = "modules/music_player/songs/".$location;
$folder = "modules/music_player/songs";
$dir=dir("./$folder/.");
$found=false;
while($filename=$dir->read()) {
	if($filename==$location){
		$found=true;		
	}
}

 

The thing is the files are put in sites/default/files. The modules/music_player/songs/ is supposed to be where it is stored, but it does not move the file like it was supposed to. So I just went about trying to work on the xml function to print the directory where the file is.

 

If you want the entire file, let me know.

Link to comment
Share on other sites

Hi,

 

I have been looking all over the code, but cannot tell where the fmp_song_name variable is being defined. Also after examining the mysql database, the module is not placing a value for fmp_song_name in the database. It is able to do so for the other song variables

 

Here is the entire module code

 

<?php
// $Id$
// Module code start

function fmp_manager_help($section = '', $arg) {
$output = '';
switch ($section) {
	case "admin/help#fmp_manager":
	return  $output = '<p>'.  t("Manage your albums"). '</p>';

	case 'admin/fmp_manager':
	return  $output =  '<p>'. t("Simply manage your Songs.<br/><br/>") . l(t('Add new song'), "admin/fmp_manager/add", array(), $destination)  .'</p>'.write_xml();

	case 'admin/fmp_albums':
	return  $output =  '<p>'. t("Create new album (s) [To add songs under any album, please follow 'Manage your songs' link.]<br/><br/>") . l(t('Add New Album'), "admin/fmp_albums/add", array(), $destination)  .'</p>'.write_xml();	
}
}

/**
* Valid permissions for this module
* @return array An array of valid permissions for the fmp_manager module
*/

function fmp_manager_perm() {
return array('administer fmp_manager' , 'access fmp_manager');
} // function fmp_manager_perm()

function fmp_manager_menu() {
//Menu for admin user

$items['admin/fmp_manager'] = array(
  'title' => 'Manage your songs',
  'description' => 'Administer fmp_manager',
  'page callback' => 'fmp_manager_admin',
  'access arguments' => array('administer fmp_manager'),
);

$items['admin/fmp_manager/add'] = array(
  'title' => 'Add fmp_manager',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('fmp_manager_edit'),
  'access arguments' => array('administer fmp_manager'),
  'type' => MENU_LOCAL_TASK
);


$items['admin/fmp_manager/edit/%'] = array(
  'title' => t('Edit fmp_manager'),
  'page callback' => 'drupal_get_form',
  'page arguments' => array('fmp_manager_edit',3),
  'access arguments' => array('administer fmp_manager'),
  'type' => MENU_CALLBACK
);

$items['admin/fmp_manager/delete/%'] = array(
  'title' => t('Delete fmp_manager'),
  'page callback' => 'drupal_get_form',
  //'page callback' => 'fmp_manager_delete_confirm',
  'page arguments' => array('fmp_manager_delete_confirm',3),
  'access arguments' => array('administer fmp_manager'),
  'type' => MENU_CALLBACK
);


//Menu for all user
$items['fmp_manager'] = array(
  'title' => t('Music Player'),
  'page callback' => 'fmp_manager_browse',
  //'page arguments' => array(1),
  'access arguments' => array('access fmp_manager'),
);


// Sub fmp_manager section
$items['admin/fmp_albums'] = array(
  'title' => 'Manage your albums',
  'description' => 'Your albums',
  'page callback' => 'fmp_albums_overview',
  'access arguments' => array('administer fmp_manager'),
);

 $items['admin/fmp_albums/add'] = array(
  'title' => 'Add New Album',
  'page callback' => 'drupal_get_form',
  'page arguments' => array('fmp_albums_edit'),
  'access arguments' => array('administer fmp_manager'),
  'type' => MENU_LOCAL_TASK
);

 $items['admin/fmp_albums/edit/%'] = array(
  'title' => t('Edit the album'),
  'page callback' => 'drupal_get_form',
  'page arguments' => array('fmp_albums_edit',3),
  'access arguments' => array('administer fmp_manager'),
  'type' => MENU_CALLBACK
);

$items['admin/fmp_albums/delete'] = array(
  'title' => t('Delete Album'),
  'page callback' => 'drupal_get_form',
  'page arguments' => array('fmp_albums_delete_confirm',3),
  'access arguments' => array('administer fmp_manager'),
  'type' => MENU_CALLBACK
);

return $items;
}

function fmp_manager_edit($edit = 0, $cid= 0) {

if ($cid) {
	$alias = fmp_manager_load($cid);
	drupal_set_title('Edit song details');
	$output = fmp_manager_form($alias);
}
else {
	drupal_set_title('Add new song');
	$output = fmp_manager_form($cid);
}
return $output;
}


function fmp_albums_edit($edit=0, $sbid = 0) {
if ($sbid) {
	$alias = fmp_albums_load($sbid);
	//pr($alias);
	drupal_set_title('Edit the album');
	$output = fmp_albums_form($alias);
}
else {
	drupal_set_title('Add New Album');
	$output = fmp_albums_form();
}
return $output;
}

/**
* Return a form for creating or editing a fmp_manager.
*/
function fmp_manager_form($edit = '') {
//pr($edit);
if ($edit == ''){
	$form['#prefix'] = '<p></p>';
}

$form['fmp_song_title'] = array(
	'#type' => 'textfield',
	'#title' => t('Title'),
	'#size' => 60,
	'#maxlength' => 255,
	'#required' => true,
	'#default_value' => $edit['fmp_song_title'],
);

$form['file'] = array(
	'#type' => 'file',
	'#title' => t('Select Song'),
	'#size' => 40,
);

$form['fmp_album_id'] = array(
	'#type' => 'select',
	'#title' => t('Select Album'),
	'#required' => true,
	'#options' => get_fmp_albums_list(),
	'#default_value' => $edit['fmp_album_id'],
);


if($edit['fmp_song_id']) {
	$form['fmp_song_id'] = array('#type' => 'hidden', '#value' => $edit['fmp_song_id']);
	$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
} else {
	$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
 }	
$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['#redirect'] = array('admin/fmp_manager', 'destination=fmp_manager');
$form['#submit'] = array('fmp_manager_form_submit');

return $form;
}
/**
* Return a form for creating or editing a sub fmp_manager category.
*/

function fmp_albums_form($edit = '') {
if ($edit == ''){
	$form['#prefix'] = '<p></p>';
}
$form['fmp_album_name'] = array(
	'#type' => 'textfield',
	'#title' => t('Album name'),
	'#required' => true,
	'#size' => 60,
	'#maxlength' => 255,
	'#default_value' => $edit['fmp_album_name'],
);
if ($edit['fmp_album_id']) {
	$form['id'] = array('#type' => 'hidden', '#value' => $edit['fmp_album_id']);
	$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
} else {
	$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
}

	$form['#submit'] = array('fmp_albums_form_submit');
	$form['#redirect'] = array('admin/fmp_albums', 'destination=fmp_albums');
return $form;
}

/**
* Menu callback; presents an overview of all fmp_managers.
*/
function fmp_manager_admin() {
return fmp_manager_overview();
}

/** Menu callback; confirms deleting fmp_manager **/

function fmp_manager_delete_confirm($frm=null,$did=0) {

$fmp_manager = fmp_manager_load($did);
//pr($fmp_manager);	
if (user_access('administer fmp_manager')) {
	$form['fmp_song_id'] = array('#type' => 'value', '#value' => $did);
	$form['#submit'] = array('fmp_manager_delete_confirm_submit');
	$form['#redirect'] = array('admin/fmp_manager', 'destination=fmp_manager');
	$output = confirm_form(
	$form,
	t('Are you sure you want to delete the song "'.$fmp_manager['fmp_song_title'] .'"?'),      
	isset($_GET['destination']) ? $_GET['destination'] : 'admin/fmp_manager',
	t('This action cannot be undone.'),
	t('Delete'),
	t('Cancel')
);
}
return $output;
}

/**
* Menu callback; confirms deleting fmp_manager
**/

function fmp_albums_delete_confirm($frm = null, $cid) {
$fmp_manager = fmp_albums_load($cid);
//pr($cid);
if (user_access('administer fmp_manager')) {
	$form['pcid'] = array('#type' => 'value', '#value' => $cid);
	$form['#submit'] = array('fmp_albums_delete_confirm_submit');
	$form['#redirect'] = array('admin/fmp_albums', 'destination=fmp_albums');		
	$output = confirm_form(
	$form,
		t('Are you sure you want to delete the album "'.$fmp_manager['sub_dept_name'] .'"?'),      
		isset($_GET['destination']) ? $_GET['destination'] : 'admin/fmp_albums',
		t('This action cannot be undone.'),
		t('Delete'),
		t('Cancel')
	);
}
return $output;
}
function fmp_manager_delete_confirm_submit($form_id, $form_values) {
if ($form_values['values']['confirm']) {
	fmp_manager_delete($form_values['values']['fmp_song_id']);
	return true;
}
}
function fmp_albums_delete_confirm_submit($form_id, $form_values) {
if ($form_values['values']['confirm']) {
	fmp_albums_delete($form_values['values']['pcid']);
	return true;
}
}
/**
* Post-confirmation; delete a fmp_manager.
*/
function fmp_manager_delete($did = 0) {
$sql="select s.fmp_song_name FROM {fmp_songs s} WHERE fmp_song_id = $did";
$result = db_query($sql);
while($l = db_fetch_object($result)) {
	$location=$l->fmp_song_name;
}	
$file = "modules/music_player/songs/".$location;
$folder = "modules/music_player/songs";
$dir=dir("./$folder/.");
$found=false;
while($filename=$dir->read()) {
	if($filename==$location){
		$found=true;		
	}
}
if($found){
	unlink($file);
}
$dir->close();
if(db_query('DELETE FROM {fmp_songs} WHERE fmp_song_id = %d', $did)) {
	drupal_set_message(t('Song has been deleted.'), 'warning');
} else {
	drupal_set_message(t('Their was an error deleting the song. Please try agin later.'), 'error');
}
}
/**
* Post-confirmation; delete a sub fmp_manager.
*/
function fmp_albums_delete($sbid = 0) {
if(db_query('DELETE FROM {fmp_albums} WHERE fmp_album_id = %d', $sbid)) {
	drupal_set_message(t('Album has been deleted successfully.'), 'warning');
} else {
	drupal_set_message(t('There was an error deleting the album. Please try agin later.'), 'error');
}
}
/**
* Fetch a specific fmp_manager from the database.
*/
function fmp_manager_load($did) {
return db_fetch_array(db_query('SELECT * FROM {fmp_songs} d WHERE d.fmp_song_id= %d', $did));
}
function fmp_manager_load_from_shortname($sName) {
//printf('SELECT * FROM {fmp_manager} d WHERE d.dept_id= %d', $did);
return db_fetch_array(db_query('SELECT * FROM {fmp_manager} d WHERE d.short_name= "%s"', $sName));
}
/**
* Fetch a specific sub fmp_manager from the database.
*/
function fmp_albums_load($sbid) {
return db_fetch_array(db_query('SELECT * FROM {fmp_albums} pc where fmp_album_id=%s',$sbid));
}
/**
* Save a fmp_manager to the database.
*/
function fmp_manager_form_submit($form_id, $form_values) {
global $user;
// pr($form_values);
/*
$validators = array(
	'file_validate_is_image' => array(),
	'file_validate_image_resolution' => array('85x85')),
	'file_validate_size' => array(30 * 1024),
);

if ($file = file_save_upload('picture_upload',$validators)) {
	// All that validation is taken care of... but image was saved using
	// file_save_upload() and was added to the files table as a
	// temporary file. We'll make a copy and let the garbage collector
	// delete the original upload.
	$info = image_get_info($file->filepath);
	//$dest= '../../music_player/songs/'.$info['name'].$info['extension'];
	file_copy($file, $dest, FILE_EXISTS_REPLACE);
};	
*/	
//   pr("<br />");

$validators = array(
	'file_validate_extensions' => array('mp3','wav','mpeg','aac'),
);

if($file = file_save_upload('file',$validators,'songs',$replace = FILE_EXISTS_RENAME)){
	//pr($file);
	$updateFile = $file->filepath;
}else{
	//pr('error');
}
//pr($_FILES);  
//pr($file);
if($form_values['values']['fmp_song_id']) {
	//update
	db_query("UPDATE {fmp_songs} SET 
	fmp_song_title = '%s', fmp_song_name = '%s', fmp_album_id = '%d'
	WHERE fmp_song_id = %d"
		, $form_values['values']['fmp_song_title'], $file->filepath, $form_values['values']['fmp_album_id']
		, $form_values['values']['fmp_song_id']
	);
	drupal_set_message('Song has been updated. ', 'status');
} else {
	//insert
	$file_location = $file->filepath;
	$pieces = explode("music_player/songs", $file_location);
	$temp = $pieces[1];
	$p = explode("./", $temp);
	$location = $p[1];		
	$query = db_query("INSERT INTO {fmp_songs} 
		(fmp_song_title, fmp_song_name, fmp_album_id,create_date)
		VALUES ('%s', '%s','%s','%d')"
		, $form_values['values']['fmp_song_title'], $location, $form_values['values']['fmp_album_id']
		, time()
	);
	if($query) {
		drupal_set_message('New song added successfully', 'status');
	} else {
		drupal_set_message('There was an error in saving your entry. Please try again later. ', 'error');
	}
}

return 'admin/fmp_manager';
}

/**
* Save a sub fmp_manager to the database.
*/
function fmp_albums_form_submit($form_id, $form_values) {	
global $user;
if($form_values['values']['id']) {
	//update
		db_query("UPDATE {fmp_albums} SET 
		fmp_album_name = '%s'
		WHERE fmp_album_id = %d"
		, $form_values['values']['fmp_album_name'], $form_values['values']['id']
	);
	drupal_set_message('Album has been updated. ', 'status');
} else {
	//insert
	$query = db_query("INSERT INTO {fmp_albums} 
	(fmp_album_name) 
	VALUES ('%s')"
	, $form_values['values']['fmp_album_name']
	);
	if($query) {
		drupal_set_message('Album has been created successfully', 'status');
	} else {
		drupal_set_message('There was an error in saving your entry. Please try again later. ', 'error');
	}
}	
return 'admin/fmp_albums';
}

/**
* Return a listing of all fmp_manager.
*/

function fmp_manager_overview() {
global $user;
//$sql = "SELECT * FROM {fmp_songs}";	
$sql = "select fmp_songs.fmp_song_id,fmp_songs.fmp_song_title,fmp_albums.fmp_album_name from fmp_songs,fmp_albums where(fmp_songs.fmp_album_id=fmp_albums.fmp_album_id)";

//$order_clause = " ORDER BY C.create_date DESC";
$order_clause = " ORDER BY fmp_song_id ASC";	
$header = array(	
	array('data' => t('File Name'), 'field' => 'fmp_song_title'),
	array('data' => t('Album')),
	array('data' => t('Operations'), 'colspan' => '3')
	);	
$sql .= tablesort_sql($header);	
/*if(!preg_match("/ORDER BY/", $sql)) {
	$sql .= $order_clause;
}*/
$result = pager_query($sql, 20);	
$destination = drupal_get_destination();
while ($data = db_fetch_object($result)) {
	$rows[] = array(
		l(t(check_plain($data->fmp_song_title)),"admin/fmp_manager"),
		check_plain($data->fmp_album_name),
		l(t('edit'), "admin/fmp_manager/edit/$data->fmp_song_id", array(), $destination), 
		l(t('delete'), "admin/fmp_manager/delete/$data->fmp_song_id", array(), $destination),	
	);
}	
if (!$rows) {
	$rows[] = array(array('data' => t('No songs added yet.'), 'colspan' => '9'));
}	
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 20, 0);
return $output;
}


function fmp_albums_overview() {
global $user;
$sql = "SELECT * FROM {fmp_albums} pc";
$order_clause = " ORDER BY pc.fmp_album_name ASC";
$header = array(
array('data' => t('Album name'), 'field' => 'fmp_album_name'),
array('data' => t('Operations'), 'colspan' => '3'));	
$sql .= tablesort_sql($header);	
if(!preg_match("/ORDER BY/", $sql)) {
	$sql .= $order_clause;
}
$result = pager_query($sql, 20);	
$destination = drupal_get_destination();
while ($data = db_fetch_object($result)) {
	$rows[] = array(
		check_plain($data->fmp_album_name),
		check_plain($data->department_name),
		l(t('edit'), "admin/fmp_albums/edit/$data->fmp_album_id", array(), $destination), 
		l(t('delete'), "admin/fmp_albums/delete/$data->fmp_album_id", array(), $destination)	  
		);
}	
if (!$rows) {
	$rows[] = array(array('data' => t('You have not created any albums yet.'), 'colspan' => '9'));
}	
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 20, 0);
return $output;
}

/**
* Return a listing of all fmp_manager.
*/
function fmp_manager_browse($shortname = '') {
global $user;
drupal_set_title('Music Player ');  	
$output = '';
$modulepath = drupal_get_path('module', 'fmp_manager');	
$flashPlayerPath = $GLOBALS['base_url'].'/'.$modulepath;
$output.='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="600" height="300" title="Music player">';
$output.= '<param name="movie" value="'.$flashPlayerPath.'/music1.swf" />
<param name="xmlPath" value="'.$flashPlayerPath.'" />
<param name="xmlName" value="'.$flashPlayerPath.'" />
<param name="quality" value="high" />
<embed src="'.$flashPlayerPath.'/music1.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="300"></embed>
</object>';	
// pr($fmp_managerArray);
//  $output = theme('fmp_manager',$fmp_managerArray);
//pr($shortname);	
return $output;  
}

function fmp_manager_browse_p2($shortname = '') {
global $user;
drupal_set_title('Player 2');  	
$output = '';
$modulepath = drupal_get_path('module', 'fmp_manager');	
$flashPlayerPath = $GLOBALS['base_url'].'/'.$modulepath;
$output.='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="600" height="300" title="flash media player">';
$output.= '<param name="movie" value="'.$flashPlayerPath.'/fmp_sampleSix.swf" />
<param name="xmlPath" value="'.$flashPlayerPath.'" />
<param name="xmlName" value="'.$flashPlayerPath.'" />
<param name="quality" value="high" />
<embed src="'.$flashPlayerPath.'/fmp_sampleSix.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="300"></embed>
</object>';
// pr($fmp_managerArray);
//  $output = theme('fmp_manager',$fmp_managerArray);
//pr($shortname);	
return $output;  
}

function fmp_manager_browse_p3($shortname = '') {
global $user;
drupal_set_title('Player 3');  
$output = '';
$modulepath = drupal_get_path('module', 'fmp_manager');	
$flashPlayerPath = $GLOBALS['base_url'].'/'.$modulepath;
$output.='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="600" height="300" title="flash media player">';
$output.= '<param name="movie" value="'.$flashPlayerPath.'/fmp_sampleThree.swf" />
<param name="xmlPath" value="'.$flashPlayerPath.'" />
<param name="xmlName" value="'.$flashPlayerPath.'" />
<param name="quality" value="high" />
<embed src="'.$flashPlayerPath.'/fmp_sampleThree.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="300"></embed>
</object>';
// pr($fmp_managerArray);
//  $output = theme('fmp_manager',$fmp_managerArray);
//pr($shortname);	
return $output;  
}

function fmp_manager_browse_p4($shortname = '') {
global $user;
drupal_set_title('Player 4');  	
$output = '';
$modulepath = drupal_get_path('module', 'fmp_manager');	
$flashPlayerPath = $GLOBALS['base_url'].'/'.$modulepath;
$output.='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="600" height="300" title="flash media player">';
$output.= '<param name="movie" value="'.$flashPlayerPath.'/fmp_sampleFour.swf" />
<param name="xmlPath" value="'.$flashPlayerPath.'" />
<param name="xmlName" value="'.$flashPlayerPath.'" />
<param name="quality" value="high" />
<embed src="'.$flashPlayerPath.'/fmp_sampleFour.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="300"></embed>
</object>';
// pr($fmp_managerArray);
//  $output = theme('fmp_manager',$fmp_managerArray);
//pr($shortname);	
return $output;  
}

function fmp_manager_browse_p5($shortname = '') {
global $user;
drupal_set_title('Player 5');  	
$output = '';
$modulepath = drupal_get_path('module', 'fmp_manager');	
$flashPlayerPath = $GLOBALS['base_url'].'/'.$modulepath;
$output.='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="600" height="300" title="flash media player">';
$output.= '<param name="movie" value="'.$flashPlayerPath.'/fmp_sampleFive.swf" />
<param name="xmlPath" value="'.$flashPlayerPath.'" />
<param name="xmlName" value="'.$flashPlayerPath.'" />
<param name="quality" value="high" />
<embed src="'.$flashPlayerPath.'/fmp_sampleFive.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="300"></embed>
</object>';
// pr($fmp_managerArray);
//  $output = theme('fmp_manager',$fmp_managerArray);
//pr($shortname);	
return $output;  
}

function fmp_manager_browse_p6($shortname = '') {
global $user;
drupal_set_title('Player 6');  	
$output = '';
$modulepath = drupal_get_path('module', 'fmp_manager');	
$flashPlayerPath = $GLOBALS['base_url'].'/'.$modulepath;
$output.='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="600" height="300" title="flash media player">';
$output.= '<param name="movie" value="'.$flashPlayerPath.'/fmp_sampleTwo.swf" />
<param name="xmlPath" value="'.$flashPlayerPath.'" />
<param name="xmlName" value="'.$flashPlayerPath.'" />
<param name="quality" value="high" />
<embed src="'.$flashPlayerPath.'/fmp_sampleTwo.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="300"></embed>
</object>';
// pr($fmp_managerArray);
//  $output = theme('fmp_manager',$fmp_managerArray);
//pr($shortname);	
return $output;  
}

function get_fmp_albums_list(){
$dept_list = array();
$dept_list[''] = '';	 
$result = db_query("SELECT * FROM {fmp_albums}");
while($dept = db_fetch_object($result)) {
	$dept_list[$dept->fmp_album_id] = $dept->fmp_album_name;
}	
return $dept_list;
}
function pr($data)
{
echo "<pre>";
print_r($data);
echo "</pre>";
}


function write_xml()
{
   $sql="select fmp_albums.fmp_album_name from fmp_albums";  
   $to_write="<?xml version=\"1.0\" ?>\n\t<songs>";  
/* when I post this, the beginning ' gets stripped off the beginning of the xml block..
so make sure it is there when you put it back in your script */   
   
   $result = db_query($sql);   
   
   while($dept = db_fetch_object($result))
   {
      $to_write .= "\n\n\t\t".'<album name="'.$dept->fmp_album_name.'">'; 
      
  $song_sql="select fmp_songs.fmp_song_name, fmp_songs.fmp_song_title from fmp_songs where fmp_songs.fmp_album_id=(select fmp_albums.fmp_album_id from fmp_albums where fmp_albums.fmp_album_name='".$dept->fmp_album_name."')";   
        //$song_sql="select * from fmp_songs,fmp_albums where fmp_songs.fmp_album_id=fmp_albums.fmp_album_id";
      $result_song = db_query($song_sql); 
      
      while($album_song = db_fetch_object($result_song))
      {
         $to_write .="\n\t\t\t".'<song display="'.$album_song->fmp_song_title.'" url="'.$album_song->fmp_song_name.'"  />';
echo 'Song: '.$album_song->fmp_song_name;
      }   
      
      $to_write .= "\n\t\t".'</album>';
   }   
   
   $to_write .= "\n\n\t".'</songs>';   
   
   echo $to_write;

   $myFile = 'modules/music_player/songlist.xml';
   $fh = fopen($myFile, 'w') or die("can't open file");
   fwrite($fh, $to_write);
   fclose($fh);
   
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.