Zend - The PHP Company




Miscellaneous

Add Code


OPML PHP Class  

Type: application
Added by: amars
Entered: 06/04/2003
Last modified: 04/12/2002
Rating: - (fewer than 3 votes)
Views: 5789
PHP class for use with OPML (Outline Processor Markup Language) files. OPML is a XML-based file format for outline-structured information. More info at http://www.opml.org


<?php

class Outline {
    var 
$outline;
    var 
$head;
    var 
$index;
    var 
$vals;
    var 
$error;
    var 
$tags=array('TITLE',
                    
'DATECREATED',
                    
'DATEMODIFIED',
                    
'OWNERNAME',
                    
'OWNEREMAIL',
                    
'EXPANSIONSTATE',
                    
'VERTSCROLLSTATE',
                    
'WINDOWTOP',
                    
'WINDOWLEFT',
                    
'WINDOWBOTTOM',
                    
'WINDOWRIGHT');

    function 
Outline($filename='') {
        if(
file_exists($filename)){
            
$this->OPMLOutlineFromFile($filename);
        } else {
            
$error="File does not exist.";
        }
    }

function 
OPMLOutlineFromFile($filename="") {
        
$handle fopen ($filename"r");
        
$contents fread ($handlefilesize ($filename));
        
fclose ($handle);

        
$p=xml_parser_create();
        
xml_parse_into_struct($p,$contents,$vals,$index);
        
xml_parser_free($p);

        
$outline=array();
        foreach(
$index['OUTLINE'] as $foo){
            if(
in_array($vals[$foo]['type'],array('open','complete'))) {
                if(empty(
$mindepth)){
                    
$mindepth=$vals[$foo]['level'];
                }
                
$this->outline[]=array('level'=>$vals[$foo]['level']-$mindepth,
                                       
'text'=>$vals[$foo]['attributes']['TEXT'],
                                       
'created'=>$vals[$foo]['attributes']['CREATED'],
                                       
'type'=>$vals[$foo]['type']);
            }
        }
        
        foreach(
$this->tags as $tag){
            
$this->head[$tag]=$vals[$index[$tag][0]];
        }
    }

}

?>



Usage Example


$outline=new Outline('daveWiner.opml');

?>
<table border=0>
<?php
foreach($outline->outline as $entry){
    
$leftspan=$entry['level'];
        for(
$x=0;$x<$leftspan;$x++){
            echo 
"&nbsp;&nbsp;&nbsp;";
        }
        echo 
$entry['type']=='open' '+ ' '- ';
        echo 
"{$entry['text']}</td>";
        echo 
"<br>n";
    
$x++;
}
?>
</table>


Rate This Script





Search



This Category All Categories