Location: PHPKode > projects > MyOWNSpace > MyOWNspace_v8.2/www/randomradio.php
<?php
/// **RANDOM PLAYSIST v.2**
/// **NO OWNER REDUNDANCY**

include "login.inc.php";
include "config.php";
$max = 5;
$page="";
$x=0;
$playlisttags = array ('title', 'annotation', 'creator', 'info', 'location', 'license');
$tracktags = array('location', 'annotation', 'image','info');
$tracktags1 = array('location', 'creator', 'image','info','album','title','annotation','identifier');
$track=array();
$randomtracks = array();
$owner=array();
$XSPF='<playlist version="1">';
$XSPF.= '
<title>MyOWNSPACE random playlist</title>
  <annotation>Self Generated Random Playlist of MyOwnSpace MUSIC</annotation>
  <creator>MyOWNSpace</creator>
  <info>http://myownspace.fr</info>
  <location>http://myownspace.fr/charts.php</location>
  <license>nopyright</license>
<trackList>   
';
for ($x=1;$x<=$max;$x++){
$i=rand(1,count($myspace));
$newowner=true;
$filename="myownmp3/".$i.".xml";
$trackdata="";
$content = '';

if(file_exists($filename)&&filesize($filename)!=0){
		
		foreach($owner as $o){
		//echo $o;
    if($o==$myspace[$i][owner]) $newowner=false;
    }
    
if  ($newowner)  {
$owner[]=$myspace[$i][owner];
if ($f = @fopen($filename, 'r')) { //lecture du fichier
//echo "reading".$i."...<br>";
			while (!feof($f)) {
				$content .= fgets($f, 4096);
			}
			fclose($f);
			// Parse PLAYLIST info
}

preg_match_all("'<track>(.*?)</track>'si", $content, $out_trackinfo);
		$j=0;///variable pour comter les tracks dune playlist
		$count= count($out_trackinfo[1]);
		if($count>0){

		$track=array();
    foreach ($out_trackinfo[1] as $trackinfo)
		//for($j=0;$j<=count($out_trackinfo[1]); $j++)
			{
			$j++;
			
			//echo $out_trackinfo[1][$j]."#<br>";
			foreach($tracktags1 as $tags)
			{
			
				preg_match("'<$tags.*?>(.*?)</$tags>'si", $out_trackinfo[1][$j],$temp);
				
				if ($temp != '') {
				$myowntracks[$tags] = $temp; // Set only if not empty
				}
				}
				//if(strstr($myowntracks[location][1],".mp3")==".mp3") {
				$track[$j][location]=$myowntracks[location][1];
				$track[$j][creator]=$myspace[$i][artiste];
				$track[$j][info]='http://myownspace.fr/'.$i;
				if($myspace[$i][image]!="")$track[$j][image]=$myspace[$i][image];
				else $track[$j][image]="http://myownspace.fr/images/unknown.gif";
				$track[$j][title]=$myowntracks[annotation][1];
				$track[$j][album]=$myspace[$i][titre];
				$track[$j][annotation]=$track[$j][creator]." - ".$track[$j][titre]." (".$track[$j][album].") ";
				$track[$j][identifier]=$i;
				$trackdata.= "<".$tags.">".$track[$j][$tags]."</".$tags.">
       // }
    		if($trackdata!="") $XSPF.= '<track>
'.$trackdata.'</track>
';		
			}


  } else $max++;  }}
else $max++; //max++; 
 }
else $max++;      



$XSPF.= '  </trackList>
</playlist>';
$filename='myownmp3/random.xml';
//writeTXT($filename,$XSPF); 
header('Content-type: application/xml');
echo $XSPF;
?>
Return current item: MyOWNSpace