Miscellaneous
|
|
|
|
<?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 ($handle, filesize ($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 " ";
}
echo $entry['type']=='open' ? '+ ' : '- ';
echo "{$entry['text']}</td>";
echo "<br>n";
$x++;
}?> </table>
|
|
|
Rate This Script
|
|
|
|