index.php

<?
include("xrns.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Renoise Stuff</title>
<style>
body{
    font-family:arial;
}
.thingcontainer{
    border-bottom: 1px solid #dddddd;
    margin:5px;
    padding:5px;
}
.title{
    color:blue;
    font-weight:bold;
    font-size:1em;
    background:#eeeeee;
    padding:4px;
}
.titledata{
    padding:4px;
}
h1{
margin:0px;
}
</style>
</head>
<body>
<h1>XRNS Reader</h1>
<a href="view.php">view source</a><hr>
<?
$xrns
=new xrns("test.xrns");
//
$format="<div class=\"thingcontainer\"><div class=\"title\">%s</div><div class=\"titledata\">%s</div>\n</div>\n";
printf($format"Song Name",$xrns->GlobalSongData->SongName);
printf($format"Artist",$xrns->GlobalSongData->Artist);
printf($format"SongComments",$xrns->GlobalSongData->SongComments);
printf($format"BPM",$xrns->GlobalSongData->BeatsPerMin);
printf($format"Ticks per line",$xrns->GlobalSongData->TicksPerLine);
printf($format"Octave",$xrns->GlobalSongData->Octave);
printf($format"EditStep",$xrns->GlobalSongData->EditStep);
printf($format"LoopCoeff",$xrns->GlobalSongData->LoopCoeff);
printf($format"LoopStart ",$xrns->GlobalSongData->LoopStart);
printf($format"ShuffleIsActive",$xrns->GlobalSongData->ShuffleIsActive);
printf($format"ShuffleAmounts",$xrns->GlobalSongData->ShuffleAmounts);
printf($format"Loop Play",$xrns->GlobalSongData->LoopPlay);
printf($format"ShowSongCommentsAfterLoading",$xrns->GlobalSongData->ShowSongCommentsAfterLoading);
printf($format"AmigaFt2CompatibilityMode",$xrns->GlobalSongData->AmigaFt2CompatibilityMode);
printf($format"AdjustVstTempoWithTPL",$xrns->GlobalSongData->AdjustVstTempoWithTPL);
printf($format"CorrectSamplePitch",$xrns->GlobalSongData->CorrectSamplePitch);
?>
</body>
</html>

xrns.php

<?
class xrns{
    private 
$debugOn=FALSE// debug Mode, not implemented yet.
    
private $fileHandler// the xrns file handler
    
private $zipObj// the ziparchive object
    
private $workPath="."// where any files inside the xrns file live
    
private $extractedfileList// array of extracted files (so you can clean up later)
    
private $songXML// Song.xml as an xml object
    
public $GlobalSongData// the GlobalSongData attribute list
    //********************************************************
    
    
function __construct($filename) {
        
// init xrns file
        
if(!class_exists("ZipArchive")){
            die(
"Class ZipArchive not found.  You must compile PHP with zip support.");
        }
           if(!
file_exists($filename)){
            die(
"file not found: <strong>$filename</strong>");
        }
        
$this->zipObj=new ZipArchive;
        
$this->fileHandler=$this->zipObj->open($filename);
        
// extract Song.xml to $this->workPath
        
$this->zipObj->extractTo($this->workPath, array("Song.xml"));
        
$this->extractedfileList[]=$this->workPath."/Song.xml";
        if(!
file_exists($this->workPath."/Song.xml")){
            die(
"Found <strong>$filename</strong><br><strong>Song.xml</strong> not found in archive, may not be valid xrns file.");
        }
        
// load xml document
        
$this->songXML = new DOMDocument;
        
$this->songXML->load($this->workPath."/Song.xml");
        
// collect global song data
        
$this->collectGlobalSongData();
    }
    
    private function 
collectGlobalSongData(){
        
$globalsongdata=$this->XMLNodetoarray('GlobalSongData');
        foreach(
$globalsongdata as $name=>$data){
            switch(
$name){
                case 
"ShuffleAmounts";
                    
$this->GlobalSongData->ShuffleAmounts=$data[0]["ShuffleAmount"];
                    break;
                case 
"SongComments":
                    
$this->GlobalSongData->SongComments=$data[0]["SongComment"];
                    break;
                default:
                    
$this->GlobalSongData->{$name}=$data[0];
                    break;
            }
        }
    }
    
    private function 
XMLNodetoarray($tagname){
        
// calls a node in an xml file and returns it as array, no attribs.
        
$itemList $this->songXML->getElementsByTagName($tagname);
        foreach(
$itemList as $elementObj){
            
$ret=$this->_XMLNodetoarray($elementObj);
        }
        return 
$ret;
    }
    
    private function 
_XMLNodetoarray($elementObj){
        
// recursive function to collect node info
        
$data=array();
        
$ret=array();
        
$itemList=$elementObj->childNodes;
        foreach(
$itemList as $thiselementObj){
            if(
$thiselementObj->hasChildNodes()){
                
$data=$this->_XMLNodetoarray($thiselementObj);
                if(
sizeof($data))$ret[$thiselementObj->nodeName][]=$data;
            }
            if(
$thiselementObj->nodeType==XML_ELEMENT_NODE && sizeof($data)<1){
                
$ret[$thiselementObj->nodeName][]=$thiselementObj->textContent;
            }
        }
        return 
$ret;
    }
    
    function 
__destruct() {
        if(
$this->zipObj)$this->zipObj->close();
        if(
$this->extractedfileList){
            foreach(
$this->extractedfileList as $key=>$thisFilename){
                
//unlink($thisFilename); // why doesn't this work?
            
}
        }
    }
}
?>