feedoutput = $feed;
$this->parse_opml($file);
$this->generate_table();
}
function parse_opml ($file)
{
$fp = fopen($file, 'r');
if (!$fp) return;
$xml = fread($fp, filesize($file));
fclose($fp);
$parser = xml_parser_create('');
$status = xml_parse_into_struct($parser, $xml, $this->vals, $this->index);
xml_parser_free($parser);
if (!$status) return;
return true;
}
function generate_table () // creates table from parsed OPML file
{
$this->html .= '
' . "\n";
$zhuaxia = false;
foreach ($this->index['OUTLINE'] as $i)
{
$type = $this->vals[$i]['type'];
if ($type == 'cdata' or $i < $this->index['BODY'][0])
continue; //skips over header informaition in OMPL file
if ($type == 'open') // This for the section headers
{
if ($this->vals[$i]['attributes']['TEXT']=='base') //hack for zhuaxia
{
$zhuaxia = true;
continue;
}
$this->html .= '- ' . $this->vals[$i]['attributes']['TEXT'] . "\n
\n";
continue;
}
if ($type == 'close')
{
$this->html .= "
\n \n";
continue;
}
if ($type == 'complete')
{
$this->count++;
//formatting for podcast feed
$title = htmlspecialchars(trim($this->vals[$i]['attributes']['TITLE']));
$text = htmlspecialchars(trim($this->vals[$i]['attributes']['TEXT']));
$htmlurl = htmlspecialchars($this->vals[$i]['attributes']['HTMLURL']);
$type = htmlspecialchars($this->vals[$i]['attributes']['TYPE']);
$xmlurl = htmlspecialchars($this->vals[$i]['attributes']['XMLURL']);
$this->html .= '- ' . $text . '';
if ($this->feedoutput) $this->html .= ' [' . $type . ']
';
}
}
if ($zhuaxia) $this->html = substr($this->html, 0, strlen($this->html)-12);
$this->html .= '
';
}
}
function showopml($file, $feed = true) {
$opml = new OPMLtoHTML($file, $feed);
echo $opml->html;
echo '共' . $opml->count . '个feed。';
}
$bl_opml_url = '';
function download_blv_opml() {
global $bl_opml_url;
$bl_opml = @file_get_contents($bl_opml_url)
;
if (!$bl_opml)
return false;
$f = @fopen(ABSPATH . 'export.opml', "w");
if (!$f) return false;
fwrite($f,$bl_opml);
fclose($f);
}
if (function_exists('wp_cron_init') and ($bl_opml_url !=
'')) add_action('wp_cron_daily', 'download_blv_opml');
?>