element; the value of each entry is an
* array of the attribute name/value pairs from the
* outline. For instance:
*
* $_BLOGROLL['foo'] =
* ['TITLE'] => 'foo'
* ['DESCRIPTION'] => 'from the outline'
* ['HTMLURL'] => 'http://example.com/blog/'
*
* et cetera.
*/
print "
\n";
ksort($_BLOGROLL);
foreach ($_BLOGROLL as $blog) {
/*
* Figure out what the anchor title attribute should be.
* Use the description if there is one, otherwise use
* the outlint title.
*/
if (isset($blog['DESCRIPTION']) && $blog['DESCRIPTION']) {
$alt = HTMLentities($blog['DESCRIPTION']);
}
else {
$alt = (isset($attr) && isset($attr['TITLE'])
? HTMLentities($attr['TITLE'])
: '');
}
/*
* Form an anchor for this outline.
*/
$url = explode('?', $blog['HTMLURL']);
for ($i = 0; $i < count($url); $i++) {
$url[$i] = HTMLentities($url[$i]);
}
$url = implode('?', $url);
$anchor = (''
. HTMLentities($blog['TITLE'])
. '');
/*
* Here's the *real* place to make personal changes.
*/
print " - $anchor
\n";
}
print "
\n";
}
$status = count($_BLOGROLL);
/*
* Nuke the global cell (ptui, ptui!)
*/
$_BLOGROLL = null;
return $status;
}
/*
* You shouldn't need to change anything from this point on.
*/
/*
* Parse the OPML file and extract the outlines from it.
*/
function parse_opml($file) {
$fp = @fopen($file, 'rB');
if (! $fp) {
return false;
}
$opml = fread($fp, 1000000);
$xp = xml_parser_create();
xml_set_element_handler($xp, '_xml_startElement', '_xml_endElement');
xml_parse($xp, $opml, true);
xml_parser_free($xp);
return true;
}
/*
* Helper functions for parsing the OPML file (which is XML).
* It's too bad we have to pollute the global namespace (variable
* $_BLOGROLL), but that's a limitation. I tried doing this OO
* inside an object, but indirect call-by-name apparently requires
* global function names. Sigh.
*
* Basically, add each outline to the $_BLOGROLL array, using
* the outline 'title' attribute as the key.
*/
function _xml_startElement($xp, $element, $attr) {
global $_BLOGROLL;
/*
* If it isn't an element, ignore it.
*/
if (strcasecmp('outline', $element)) {
return;
}
$_BLOGROLL[$attr['TITLE']] = $attr;
}
function _xml_endElement($xp, $element) {
return;
}
/*
* Local Variables:
* mode: C
* c-file-style: "bsd"
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
?>