From 27418e733364a1af6bef69ac1a89fcb28e4d5dd2 Mon Sep 17 00:00:00 2001 From: Mike Little Date: Wed, 10 Dec 2003 00:43:15 +0000 Subject: [PATCH] Updated links import. Now should be able to tackle any OPML git-svn-id: https://develop.svn.wordpress.org/trunk@596 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/links.import.php | 93 +++++++++++++++++------------------ wp-admin/links.parse.opml.php | 64 ++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 48 deletions(-) create mode 100644 wp-admin/links.parse.opml.php diff --git a/wp-admin/links.import.php b/wp-admin/links.import.php index 350437e923..7bd3ca1710 100644 --- a/wp-admin/links.import.php +++ b/wp-admin/links.import.php @@ -9,7 +9,7 @@ $parent_file = 'linkmanager.php'; $title = 'Import Blogroll'; $this_file = 'links.import.php'; -$step = $HTTP_GET_VARS['step']; +$step = $HTTP_POST_VARS['step']; if (!$step) $step = 0; ?> @@ -33,7 +33,9 @@ switch ($step) {

On this page you can import your blogroll.

-
+ + +
  1. Go to Blogrolling.com and sign in. Once you've done that, click on Get Code, and then @@ -43,20 +45,14 @@ switch ($step) { that in the 'Welcome Back' box on the right, click on share, and then look for the OPML link (favorites.opml).
  2. -
  3. Select that text and copy it or copy the link/shortcut into the box below.
    - Your OPML code: + Your OPML URL:
  4. -
  5. Did you use - -  or  - - ? +
  6. + or you can upload an OPML file from your desktop aggregator:
    + +
  7. Now select a category you want to put these links in.
    @@ -70,7 +66,7 @@ blo.gs } // end foreach ?> - +
  8. @@ -92,59 +88,60 @@ blo.gs

    Importing...

    You need to supply your OPML url. Press back on your browser and try again

    \n"; - } - else - { - - $opml = implode('', file($opml_url)); - // Updated for new format thanks to Rantor http://wordpress.org/support/2/769 - if ($opmltype == 'blogrolling') { - preg_match_all('//', $opml, $items); - $names = $items[1]; - $types = $items[2]; - $urls = $items[3]; - $titles = $items[5]; - $targets = $items[6]; - } else { - preg_match_all('//', $opml, $items); - $types = $items[1]; - $names = $items[2]; - $urls = $items[3]; - } + $opml_url = $HTTP_POST_VARS['opml_url']; + if (isset($opml_url) && $opml_url != '') { + $blogrolling = true; + } + else // try to get the upload file. + { + $uploaddir = $fileupload_realpath; + $uploadfile = $uploaddir.'/'.$_FILES['userfile']['name']; + + if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) + { + //echo "Upload successful.

    "; + $blogrolling = false; + $opml_url = $uploadfile; + } else { + echo "Upload error

    "; + } + } + + if (isset($opml_url) && $opml_url != '') { + $opml = implode('', file($opml_url)); + include_once('links.parse.opml.php'); + $link_count = count($names); for ($i = 0; $i < $link_count; $i++) { if ('Last' == substr($titles[$i], 0, 4)) $titles[$i] = ''; - if ('http' == substr($titles[$i], 0, 4)) + if ('http' == substr($titles[$i], 0, 4)) $titles[$i] = ''; - //echo "INSERT INTO $tablelinks (link_url, link_name, link_target, link_category, link_description, link_owner) VALUES('{$urls[$i]}', '{$names[$i]}', '{$targets[$i]}', $cat_id, '{$titles[$i]}', \$user_ID)
    \n"; $query = "INSERT INTO $tablelinks (link_url, link_name, link_target, link_category, link_description, link_owner) - VALUES('{$urls[$i]}', '".addslashes($names[$i])."', '{$targets[$i]}', $cat_id, '".addslashes($titles[$i])."', $user_ID)\n"; + VALUES('{$urls[$i]}', '".addslashes($names[$i])."', '', $cat_id, '".addslashes($descriptions[$i])."', $user_ID)\n"; $result = $wpdb->query($query); - echo "

    Inserted {$names[$i]}

    "; + echo "

    Inserted {$names[$i]}

    "; } ?>

    Inserted links into category . All done! Go manage those links.

    + } // end if got url + else + { + echo "

    You need to supply your OPML url. Press back on your browser and try again

    \n"; + } // end else -
+?> + \ No newline at end of file diff --git a/wp-admin/links.parse.opml.php b/wp-admin/links.parse.opml.php new file mode 100644 index 0000000000..161b7d9acd --- /dev/null +++ b/wp-admin/links.parse.opml.php @@ -0,0 +1,64 @@ + 'URL', + 'link_name' => 'TEXT', + 'link_target' => 'TARGET', + 'link_description' => 'DESCRIPTION' + ); + +$map = $opml_map; + +/** + ** startElement() + ** Callback function. Called at the start of a new xml tag. + **/ +function startElement($parser, $tagName, $attrs) { + global $updated_timestamp, $all_links, $map; + global $names, $urls, $targets, $descriptions; + + if ($tagName == 'OUTLINE') { + if ($map['link_url'] != '') + $link_url = $attrs[$map['link_url']]; + if ($map['link_name'] != '') + $link_name = $attrs[$map['link_name']]; + if ($map['link_target'] != '') + $link_target = $attrs[$map['link_target']]; + if ($map['link_description'] != '') + $link_description = $attrs[$map['link_description']]; + //echo("got data: link_url = [$link_url], link_name = [$link_name], link_target = [$link_target], link_description = [$link_description]
\n"); + // save the data away. + $names[] = $link_name; + $urls[] = $link_url; + $targets[] = $link_target; + $descriptions[] = $link_description; + } +} + +/** + ** endElement() + ** Callback function. Called at the end of an xml tag. + **/ +function endElement($parser, $tagName) { + // nothing to do. +} + +// Create an XML parser +$xml_parser = xml_parser_create(); + +// Set the functions to handle opening and closing tags +xml_set_element_handler($xml_parser, "startElement", "endElement"); + +xml_parse($xml_parser, $opml, true) + or echo(sprintf("XML error: %s at line %d", + xml_error_string(xml_get_error_code($xml_parser)), + xml_get_current_line_number($xml_parser))); + +// Free up memory used by the XML parser +xml_parser_free($xml_parser); +?> \ No newline at end of file