mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Parse OPML XML files and store in globals.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /** Load WordPress Bootstrap */
mp-wp_genesis 10 require_once('../wp-load.php');
mp-wp_genesis 11
mp-wp_genesis 12 global $opml, $map;
mp-wp_genesis 13
mp-wp_genesis 14 // columns we wish to find are: link_url, link_name, link_target, link_description
mp-wp_genesis 15 // we need to map XML attribute names to our columns
mp-wp_genesis 16 $opml_map = array('URL' => 'link_url',
mp-wp_genesis 17 'HTMLURL' => 'link_url',
mp-wp_genesis 18 'TEXT' => 'link_name',
mp-wp_genesis 19 'TITLE' => 'link_name',
mp-wp_genesis 20 'TARGET' => 'link_target',
mp-wp_genesis 21 'DESCRIPTION' => 'link_description',
mp-wp_genesis 22 'XMLURL' => 'link_rss'
mp-wp_genesis 23 );
mp-wp_genesis 24
mp-wp_genesis 25 $map = $opml_map;
mp-wp_genesis 26
mp-wp_genesis 27 /**
mp-wp_genesis 28 * XML callback function for the start of a new XML tag.
mp-wp_genesis 29 *
mp-wp_genesis 30 * @since unknown
mp-wp_genesis 31 * @access private
mp-wp_genesis 32 *
mp-wp_genesis 33 * @uses $updated_timestamp Not used inside function.
mp-wp_genesis 34 * @uses $all_links Not used inside function.
mp-wp_genesis 35 * @uses $map Stores names of attributes to use.
mp-wp_genesis 36 * @global array $names
mp-wp_genesis 37 * @global array $urls
mp-wp_genesis 38 * @global array $targets
mp-wp_genesis 39 * @global array $descriptions
mp-wp_genesis 40 * @global array $feeds
mp-wp_genesis 41 *
mp-wp_genesis 42 * @param mixed $parser XML Parser resource.
mp-wp_genesis 43 * @param string $tagName XML element name.
mp-wp_genesis 44 * @param array $attrs XML element attributes.
mp-wp_genesis 45 */
mp-wp_genesis 46 function startElement($parser, $tagName, $attrs) {
mp-wp_genesis 47 global $updated_timestamp, $all_links, $map;
mp-wp_genesis 48 global $names, $urls, $targets, $descriptions, $feeds;
mp-wp_genesis 49
mp-wp_genesis 50 if ($tagName == 'OUTLINE') {
mp-wp_genesis 51 foreach (array_keys($map) as $key) {
mp-wp_genesis 52 if (isset($attrs[$key])) {
mp-wp_genesis 53 $$map[$key] = $attrs[$key];
mp-wp_genesis 54 }
mp-wp_genesis 55 }
mp-wp_genesis 56
mp-wp_genesis 57 //echo("got data: link_url = [$link_url], link_name = [$link_name], link_target = [$link_target], link_description = [$link_description]<br />\n");
mp-wp_genesis 58
mp-wp_genesis 59 // save the data away.
mp-wp_genesis 60 $names[] = $link_name;
mp-wp_genesis 61 $urls[] = $link_url;
mp-wp_genesis 62 $targets[] = $link_target;
mp-wp_genesis 63 $feeds[] = $link_rss;
mp-wp_genesis 64 $descriptions[] = $link_description;
mp-wp_genesis 65 } // end if outline
mp-wp_genesis 66 }
mp-wp_genesis 67
mp-wp_genesis 68 /**
mp-wp_genesis 69 * XML callback function that is called at the end of a XML tag.
mp-wp_genesis 70 *
mp-wp_genesis 71 * @since unknown
mp-wp_genesis 72 * @access private
mp-wp_genesis 73 * @package WordPress
mp-wp_genesis 74 * @subpackage Dummy
mp-wp_genesis 75 *
mp-wp_genesis 76 * @param mixed $parser XML Parser resource.
mp-wp_genesis 77 * @param string $tagName XML tag name.
mp-wp_genesis 78 */
mp-wp_genesis 79 function endElement($parser, $tagName) {
mp-wp_genesis 80 // nothing to do.
mp-wp_genesis 81 }
mp-wp_genesis 82
mp-wp_genesis 83 // Create an XML parser
mp-wp_genesis 84 $xml_parser = xml_parser_create();
mp-wp_genesis 85
mp-wp_genesis 86 // Set the functions to handle opening and closing tags
mp-wp_genesis 87 xml_set_element_handler($xml_parser, "startElement", "endElement");
mp-wp_genesis 88
mp-wp_genesis 89 if (!xml_parse($xml_parser, $opml, true)) {
mp-wp_genesis 90 echo(sprintf(__('XML error: %1$s at line %2$s'),
mp-wp_genesis 91 xml_error_string(xml_get_error_code($xml_parser)),
mp-wp_genesis 92 xml_get_current_line_number($xml_parser)));
mp-wp_genesis 93 }
mp-wp_genesis 94
mp-wp_genesis 95 // Free up memory used by the XML parser
mp-wp_genesis 96 xml_parser_free($xml_parser);
mp-wp_genesis 97 ?>