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
This commit is contained in:
parent
652d170af2
commit
27418e7333
|
@ -9,7 +9,7 @@ $parent_file = 'linkmanager.php';
|
||||||
$title = 'Import Blogroll';
|
$title = 'Import Blogroll';
|
||||||
$this_file = 'links.import.php';
|
$this_file = 'links.import.php';
|
||||||
|
|
||||||
$step = $HTTP_GET_VARS['step'];
|
$step = $HTTP_POST_VARS['step'];
|
||||||
if (!$step) $step = 0;
|
if (!$step) $step = 0;
|
||||||
?>
|
?>
|
||||||
<?php
|
<?php
|
||||||
|
@ -20,7 +20,7 @@ switch ($step) {
|
||||||
include_once('b2header.php');
|
include_once('b2header.php');
|
||||||
if ($user_level < get_settings('links_minadminlevel'))
|
if ($user_level < get_settings('links_minadminlevel'))
|
||||||
die ("Cheatin’ uh?");
|
die ("Cheatin’ uh?");
|
||||||
|
|
||||||
$opmltype = 'blogrolling'; // default.
|
$opmltype = 'blogrolling'; // default.
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
@ -33,7 +33,9 @@ switch ($step) {
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
|
|
||||||
<h3>On this page you can import your blogroll.</h3>
|
<h3>On this page you can import your blogroll.</h3>
|
||||||
<form name="blogroll" action="links.import.php" method="get">
|
<!-- <form name="blogroll" action="links.import.php" method="get"> -->
|
||||||
|
<form enctype="multipart/form-data" action="links.import.php" method="post" name="blogroll">
|
||||||
|
|
||||||
<ol>
|
<ol>
|
||||||
<li>Go to <a href="http://www.blogrolling.com">Blogrolling.com</a>
|
<li>Go to <a href="http://www.blogrolling.com">Blogrolling.com</a>
|
||||||
and sign in. Once you've done that, click on <strong>Get Code</strong>, and then
|
and sign in. Once you've done that, click on <strong>Get Code</strong>, and then
|
||||||
|
@ -43,20 +45,14 @@ switch ($step) {
|
||||||
that in the 'Welcome Back' box on the right, click on <strong>share</strong>, and then
|
that in the 'Welcome Back' box on the right, click on <strong>share</strong>, and then
|
||||||
look for the <strong><abbr title="Outline Processor Markup Language">OPML</abbr>
|
look for the <strong><abbr title="Outline Processor Markup Language">OPML</abbr>
|
||||||
link</strong> (favorites.opml)<?php echo gethelp_link($this_file,'opml_code');?>.</li>
|
link</strong> (favorites.opml)<?php echo gethelp_link($this_file,'opml_code');?>.</li>
|
||||||
|
|
||||||
<li>Select that text and copy it or copy the link/shortcut into the box below.<br />
|
<li>Select that text and copy it or copy the link/shortcut into the box below.<br />
|
||||||
<input type="hidden" name="step" value="1" />
|
<input type="hidden" name="step" value="1" />
|
||||||
Your OPML code:<?php echo gethelp_link($this_file,'opml_code');?> <input type="text" name="opml_url" size="65" />
|
Your OPML URL:<?php echo gethelp_link($this_file,'opml_code');?> <input type="text" name="opml_url" size="65" />
|
||||||
</li>
|
</li>
|
||||||
<li>Did you use
|
<li>
|
||||||
<label>
|
<strong>or</strong> you can upload an OPML file from your desktop aggregator:<br />
|
||||||
<input type="radio" name="opmltype" value="blogrolling" <?php echo(($opmltype == 'blogrolling') ? 'checked="checked"' : ''); ?>>
|
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
|
||||||
blogrolling.com</label>
|
<label>Upload this file: <input name="userfile" type="file" /></label>
|
||||||
or
|
|
||||||
<label>
|
|
||||||
<input type="radio" name="opmltype" value="blo.gs" <?php echo(($link_target == 'blo.gs') ? 'checked="checked"' : ''); ?>>
|
|
||||||
blo.gs</label>
|
|
||||||
?
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li>Now select a category you want to put these links in.<br />
|
<li>Now select a category you want to put these links in.<br />
|
||||||
|
@ -70,7 +66,7 @@ blo.gs</label>
|
||||||
} // end foreach
|
} // end foreach
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li><input type="submit" name="submit" value="Import!" /><?php echo gethelp_link($this_file,'import');?></li>
|
<li><input type="submit" name="submit" value="Import!" /><?php echo gethelp_link($this_file,'import');?></li>
|
||||||
|
@ -92,59 +88,60 @@ blo.gs</label>
|
||||||
|
|
||||||
<h3>Importing...</h3>
|
<h3>Importing...</h3>
|
||||||
<?php
|
<?php
|
||||||
$cat_id = $HTTP_GET_VARS['cat_id'];
|
$cat_id = $HTTP_POST_VARS['cat_id'];
|
||||||
if (($cat_id == '') || ($cat_id == 0)) {
|
if (($cat_id == '') || ($cat_id == 0)) {
|
||||||
$cat_id = 1;
|
$cat_id = 1;
|
||||||
}
|
}
|
||||||
$opmltype = $HTTP_GET_VARS['opmltype'];
|
|
||||||
if ($opmltype == '')
|
|
||||||
$opmltype = 'blogrolling';
|
|
||||||
$opml_url = $HTTP_GET_VARS['opml_url'];
|
|
||||||
if ($opml_url == '') {
|
|
||||||
echo "<p>You need to supply your OPML url. Press back on your browser and try again</p>\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
$opml = implode('', file($opml_url));
|
|
||||||
|
|
||||||
// Updated for new format thanks to Rantor http://wordpress.org/support/2/769
|
$opml_url = $HTTP_POST_VARS['opml_url'];
|
||||||
if ($opmltype == 'blogrolling') {
|
if (isset($opml_url) && $opml_url != '') {
|
||||||
preg_match_all('/<outline text="(.*?)" type="(.*?)" url="(.*?)" (lastmod="(.*?)"|) target="(.*?)"*? \/>/', $opml, $items);
|
$blogrolling = true;
|
||||||
$names = $items[1];
|
}
|
||||||
$types = $items[2];
|
else // try to get the upload file.
|
||||||
$urls = $items[3];
|
{
|
||||||
$titles = $items[5];
|
$uploaddir = $fileupload_realpath;
|
||||||
$targets = $items[6];
|
$uploadfile = $uploaddir.'/'.$_FILES['userfile']['name'];
|
||||||
} else {
|
|
||||||
preg_match_all('/<outline type="(.*?)" text="(.*?)" url="(.*?)" \/>/', $opml, $items);
|
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
|
||||||
$types = $items[1];
|
{
|
||||||
$names = $items[2];
|
//echo "Upload successful.<p />";
|
||||||
$urls = $items[3];
|
$blogrolling = false;
|
||||||
}
|
$opml_url = $uploadfile;
|
||||||
|
} else {
|
||||||
|
echo "Upload error<p />";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($opml_url) && $opml_url != '') {
|
||||||
|
$opml = implode('', file($opml_url));
|
||||||
|
include_once('links.parse.opml.php');
|
||||||
|
|
||||||
$link_count = count($names);
|
$link_count = count($names);
|
||||||
for ($i = 0; $i < $link_count; $i++) {
|
for ($i = 0; $i < $link_count; $i++) {
|
||||||
if ('Last' == substr($titles[$i], 0, 4))
|
if ('Last' == substr($titles[$i], 0, 4))
|
||||||
$titles[$i] = '';
|
$titles[$i] = '';
|
||||||
if ('http' == substr($titles[$i], 0, 4))
|
if ('http' == substr($titles[$i], 0, 4))
|
||||||
$titles[$i] = '';
|
$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)<br />\n";
|
|
||||||
$query = "INSERT INTO $tablelinks (link_url, link_name, link_target, link_category, link_description, link_owner)
|
$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);
|
$result = $wpdb->query($query);
|
||||||
echo "<p>Inserted <strong>{$names[$i]}</strong></p>";
|
echo "<p>Inserted <strong>{$names[$i]}</strong></p>";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<p>Inserted <?php echo $link_count ?> links into category <?php echo $cat_id; ?>. All done! Go <a href="linkmanager.php">manage those links</a>.</p>
|
<p>Inserted <?php echo $link_count ?> links into category <?php echo $cat_id; ?>. All done! Go <a href="linkmanager.php">manage those links</a>.</p>
|
||||||
<?php
|
<?php
|
||||||
} // end else got url
|
} // end if got url
|
||||||
?>
|
else
|
||||||
|
{
|
||||||
|
echo "<p>You need to supply your OPML url. Press back on your browser and try again</p>\n";
|
||||||
|
} // end else
|
||||||
|
|
||||||
</div>
|
?>
|
||||||
<?php
|
<?php
|
||||||
break;
|
break;
|
||||||
} // end case 1
|
} // end case 1
|
||||||
} // end switch
|
} // end switch
|
||||||
?>
|
?>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
require_once('../wp-config.php');
|
||||||
|
require_once($abspath.$b2inc.'/b2functions.php');
|
||||||
|
|
||||||
|
// columns we wish to find are: link_url, link_name, link_target, link_description
|
||||||
|
// we need to map XML attribute names to our columns
|
||||||
|
// if we are doing OPML use this map
|
||||||
|
$opml_map = array(
|
||||||
|
'link_url' => '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]<br />\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);
|
||||||
|
?>
|
Loading…
Reference in New Issue