PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/link-parse-opml.php

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