home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-admin / link-parse-opml.php < prev    next >
Encoding:
PHP Script  |  2008-05-21  |  1.7 KB  |  66 lines

  1. <?php
  2. require_once('../wp-load.php');
  3.  
  4. // columns we wish to find are:  link_url, link_name, link_target, link_description
  5. // we need to map XML attribute names to our columns
  6. $opml_map = array('URL'         => 'link_url',
  7.     'HTMLURL'     => 'link_url',
  8.     'TEXT'        => 'link_name',
  9.     'TITLE'       => 'link_name',
  10.     'TARGET'      => 'link_target',
  11.     'DESCRIPTION' => 'link_description',
  12.     'XMLURL'      => 'link_rss'
  13. );
  14.  
  15. $map = $opml_map;
  16.  
  17. /**
  18.  ** startElement()
  19.  ** Callback function. Called at the start of a new xml tag.
  20.  **/
  21. function startElement($parser, $tagName, $attrs) {
  22.     global $updated_timestamp, $all_links, $map;
  23.     global $names, $urls, $targets, $descriptions, $feeds;
  24.  
  25.     if ($tagName == 'OUTLINE') {
  26.         foreach (array_keys($map) as $key) {
  27.             if (isset($attrs[$key])) {
  28.                 $$map[$key] = $attrs[$key];
  29.             }
  30.         }
  31.  
  32.         //echo("got data: link_url = [$link_url], link_name = [$link_name], link_target = [$link_target], link_description = [$link_description]<br />\n");
  33.  
  34.         // save the data away.
  35.         $names[] = $link_name;
  36.         $urls[] = $link_url;
  37.         $targets[] = $link_target;
  38.         $feeds[] = $link_rss;
  39.         $descriptions[] = $link_description;
  40.     } // end if outline
  41. }
  42.  
  43. /**
  44.  ** endElement()
  45.  ** Callback function. Called at the end of an xml tag.
  46.  **/
  47. function endElement($parser, $tagName) {
  48.     // nothing to do.
  49. }
  50.  
  51. // Create an XML parser
  52. $xml_parser = xml_parser_create();
  53.  
  54. // Set the functions to handle opening and closing tags
  55. xml_set_element_handler($xml_parser, "startElement", "endElement");
  56.  
  57. if (!xml_parse($xml_parser, $opml, true)) {
  58.     echo(sprintf(__('XML error: %1$s at line %2$s'),
  59.     xml_error_string(xml_get_error_code($xml_parser)),
  60.     xml_get_current_line_number($xml_parser)));
  61. }
  62.  
  63. // Free up memory used by the XML parser
  64. xml_parser_free($xml_parser);
  65. ?>
  66.