web/wp-links-opml.php
author ymh <ymh.work@gmail.com>
Mon, 22 Mar 2010 16:36:28 +0100
changeset 5 ac511f1ccc8e
parent 1 0d28b7c10758
permissions -rw-r--r--
add hgignore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
0d28b7c10758 First commit
ymh
parents:
diff changeset
     1
<?php
0d28b7c10758 First commit
ymh
parents:
diff changeset
     2
/**
0d28b7c10758 First commit
ymh
parents:
diff changeset
     3
 * Outputs the OPML XML format for getting the links defined in the link
0d28b7c10758 First commit
ymh
parents:
diff changeset
     4
 * administration. This can be used to export links from one blog over to
0d28b7c10758 First commit
ymh
parents:
diff changeset
     5
 * another. Links aren't exported by the WordPress export, so this file handles
0d28b7c10758 First commit
ymh
parents:
diff changeset
     6
 * that.
0d28b7c10758 First commit
ymh
parents:
diff changeset
     7
 *
0d28b7c10758 First commit
ymh
parents:
diff changeset
     8
 * This file is not added by default to WordPress theme pages when outputting
0d28b7c10758 First commit
ymh
parents:
diff changeset
     9
 * feed links. It will have to be added manually for browsers and users to pick
0d28b7c10758 First commit
ymh
parents:
diff changeset
    10
 * up that this file exists.
0d28b7c10758 First commit
ymh
parents:
diff changeset
    11
 *
0d28b7c10758 First commit
ymh
parents:
diff changeset
    12
 * @package WordPress
0d28b7c10758 First commit
ymh
parents:
diff changeset
    13
 */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    14
0d28b7c10758 First commit
ymh
parents:
diff changeset
    15
if (empty($wp)) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
    16
	require_once('./wp-load.php');
0d28b7c10758 First commit
ymh
parents:
diff changeset
    17
	wp();
0d28b7c10758 First commit
ymh
parents:
diff changeset
    18
}
0d28b7c10758 First commit
ymh
parents:
diff changeset
    19
0d28b7c10758 First commit
ymh
parents:
diff changeset
    20
header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
0d28b7c10758 First commit
ymh
parents:
diff changeset
    21
$link_cat = $_GET['link_cat'];
0d28b7c10758 First commit
ymh
parents:
diff changeset
    22
if ((empty ($link_cat)) || ($link_cat == 'all') || ($link_cat == '0')) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
    23
	$link_cat = '';
0d28b7c10758 First commit
ymh
parents:
diff changeset
    24
} else { // be safe
0d28b7c10758 First commit
ymh
parents:
diff changeset
    25
	$link_cat = '' . urldecode($link_cat) . '';
0d28b7c10758 First commit
ymh
parents:
diff changeset
    26
	$link_cat = intval($link_cat);
0d28b7c10758 First commit
ymh
parents:
diff changeset
    27
}
0d28b7c10758 First commit
ymh
parents:
diff changeset
    28
?><?php echo '<?xml version="1.0"?'.">\n"; ?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    29
<?php the_generator( 'comment' ); ?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    30
<opml version="1.0">
0d28b7c10758 First commit
ymh
parents:
diff changeset
    31
	<head>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    32
		<title>Links for <?php echo esc_attr(get_bloginfo('name', 'display').$cat_name); ?></title>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    33
		<dateCreated><?php echo gmdate("D, d M Y H:i:s"); ?> GMT</dateCreated>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    34
	</head>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    35
	<body>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    36
<?php
0d28b7c10758 First commit
ymh
parents:
diff changeset
    37
0d28b7c10758 First commit
ymh
parents:
diff changeset
    38
if (empty ($link_cat))
0d28b7c10758 First commit
ymh
parents:
diff changeset
    39
	$cats = get_categories("type=link&hierarchical=0");
0d28b7c10758 First commit
ymh
parents:
diff changeset
    40
else
0d28b7c10758 First commit
ymh
parents:
diff changeset
    41
	$cats = get_categories('type=link&hierarchical=0&include='.$link_cat);
0d28b7c10758 First commit
ymh
parents:
diff changeset
    42
0d28b7c10758 First commit
ymh
parents:
diff changeset
    43
foreach ((array) $cats as $cat) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
    44
	$catname = apply_filters('link_category', $cat->name);
0d28b7c10758 First commit
ymh
parents:
diff changeset
    45
0d28b7c10758 First commit
ymh
parents:
diff changeset
    46
?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    47
<outline type="category" title="<?php echo esc_attr($catname); ?>">
0d28b7c10758 First commit
ymh
parents:
diff changeset
    48
<?php
0d28b7c10758 First commit
ymh
parents:
diff changeset
    49
0d28b7c10758 First commit
ymh
parents:
diff changeset
    50
	$bookmarks = get_bookmarks("category={$cat->term_id}");
0d28b7c10758 First commit
ymh
parents:
diff changeset
    51
	foreach ((array) $bookmarks as $bookmark) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
    52
		$title = esc_attr(apply_filters('link_title', $bookmark->link_name));
0d28b7c10758 First commit
ymh
parents:
diff changeset
    53
?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    54
	<outline text="<?php echo $title; ?>" type="link" xmlUrl="<?php echo esc_attr($bookmark->link_rss); ?>" htmlUrl="<?php echo esc_attr($bookmark->link_url); ?>" updated="<?php if ('0000-00-00 00:00:00' != $bookmark->link_updated) echo $bookmark->link_updated; ?>" />
0d28b7c10758 First commit
ymh
parents:
diff changeset
    55
<?php
0d28b7c10758 First commit
ymh
parents:
diff changeset
    56
0d28b7c10758 First commit
ymh
parents:
diff changeset
    57
	}
0d28b7c10758 First commit
ymh
parents:
diff changeset
    58
?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    59
</outline>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    60
<?php
0d28b7c10758 First commit
ymh
parents:
diff changeset
    61
0d28b7c10758 First commit
ymh
parents:
diff changeset
    62
}
0d28b7c10758 First commit
ymh
parents:
diff changeset
    63
?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    64
</body>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    65
</opml>