wp/wp-links-opml.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    12  * @package WordPress
    12  * @package WordPress
    13  */
    13  */
    14 
    14 
    15 require_once( dirname( __FILE__ ) . '/wp-load.php' );
    15 require_once( dirname( __FILE__ ) . '/wp-load.php' );
    16 
    16 
    17 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
    17 header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
    18 $link_cat = '';
    18 $link_cat = '';
    19 if ( !empty($_GET['link_cat']) ) {
    19 if ( ! empty( $_GET['link_cat'] ) ) {
    20 	$link_cat = $_GET['link_cat'];
    20 	$link_cat = $_GET['link_cat'];
    21 	if ( !in_array($link_cat, array('all', '0')) )
    21 	if ( ! in_array( $link_cat, array( 'all', '0' ) ) ) {
    22 		$link_cat = absint( (string)urldecode($link_cat) );
    22 		$link_cat = absint( (string) urldecode( $link_cat ) );
       
    23 	}
    23 }
    24 }
    24 
    25 
    25 echo '<?xml version="1.0"?'.">\n";
    26 echo '<?xml version="1.0"?' . ">\n";
    26 ?>
    27 ?>
    27 <opml version="1.0">
    28 <opml version="1.0">
    28 	<head>
    29 	<head>
    29 		<title><?php
    30 		<title>
    30 			/* translators: 1: Site name */
    31 		<?php
    31 			printf( __('Links for %s'), esc_attr(get_bloginfo('name', 'display')) );
    32 			/* translators: %s: site name */
    32 		?></title>
    33 			printf( __( 'Links for %s' ), esc_attr( get_bloginfo( 'name', 'display' ) ) );
    33 		<dateCreated><?php echo gmdate("D, d M Y H:i:s"); ?> GMT</dateCreated>
    34 		?>
       
    35 		</title>
       
    36 		<dateCreated><?php echo gmdate( 'D, d M Y H:i:s' ); ?> GMT</dateCreated>
    34 		<?php
    37 		<?php
    35 		/**
    38 		/**
    36 		 * Fires in the OPML header.
    39 		 * Fires in the OPML header.
    37 		 *
    40 		 *
    38 		 * @since 3.0.0
    41 		 * @since 3.0.0
    40 		do_action( 'opml_head' );
    43 		do_action( 'opml_head' );
    41 		?>
    44 		?>
    42 	</head>
    45 	</head>
    43 	<body>
    46 	<body>
    44 <?php
    47 <?php
    45 if ( empty($link_cat) )
    48 if ( empty( $link_cat ) ) {
    46 	$cats = get_categories(array('taxonomy' => 'link_category', 'hierarchical' => 0));
    49 	$cats = get_categories(
    47 else
    50 		array(
    48 	$cats = get_categories(array('taxonomy' => 'link_category', 'hierarchical' => 0, 'include' => $link_cat));
    51 			'taxonomy'     => 'link_category',
       
    52 			'hierarchical' => 0,
       
    53 		)
       
    54 	);
       
    55 } else {
       
    56 	$cats = get_categories(
       
    57 		array(
       
    58 			'taxonomy'     => 'link_category',
       
    59 			'hierarchical' => 0,
       
    60 			'include'      => $link_cat,
       
    61 		)
       
    62 	);
       
    63 }
    49 
    64 
    50 foreach ( (array)$cats as $cat ) :
    65 foreach ( (array) $cats as $cat ) :
    51 	/**
    66 	/** This filter is documented in wp-includes/bookmark-template.php */
    52 	 * Filters the OPML outline link category name.
       
    53 	 *
       
    54 	 * @since 2.2.0
       
    55 	 *
       
    56 	 * @param string $catname The OPML outline category name.
       
    57 	 */
       
    58 	$catname = apply_filters( 'link_category', $cat->name );
    67 	$catname = apply_filters( 'link_category', $cat->name );
    59 
    68 
    60 ?>
    69 	?>
    61 <outline type="category" title="<?php echo esc_attr($catname); ?>">
    70 <outline type="category" title="<?php echo esc_attr( $catname ); ?>">
    62 <?php
    71 	<?php
    63 	$bookmarks = get_bookmarks(array("category" => $cat->term_id));
    72 	$bookmarks = get_bookmarks( array( 'category' => $cat->term_id ) );
    64 	foreach ( (array)$bookmarks as $bookmark ) :
    73 	foreach ( (array) $bookmarks as $bookmark ) :
    65 		/**
    74 		/**
    66 		 * Filters the OPML outline link title text.
    75 		 * Filters the OPML outline link title text.
    67 		 *
    76 		 *
    68 		 * @since 2.2.0
    77 		 * @since 2.2.0
    69 		 *
    78 		 *
    70 		 * @param string $title The OPML outline title text.
    79 		 * @param string $title The OPML outline title text.
    71 		 */
    80 		 */
    72 		$title = apply_filters( 'link_title', $bookmark->link_name );
    81 		$title = apply_filters( 'link_title', $bookmark->link_name );
    73 ?>
    82 		?>
    74 	<outline text="<?php echo esc_attr($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; ?>" />
    83 <outline text="<?php echo esc_attr( $title ); ?>" type="link" xmlUrl="<?php echo esc_attr( $bookmark->link_rss ); ?>" htmlUrl="<?php echo esc_attr( $bookmark->link_url ); ?>" updated="
    75 <?php
    84 							<?php
       
    85 							if ( '0000-00-00 00:00:00' != $bookmark->link_updated ) {
       
    86 								echo $bookmark->link_updated;}
       
    87 							?>
       
    88 " />
       
    89 		<?php
    76 	endforeach; // $bookmarks
    90 	endforeach; // $bookmarks
    77 ?>
    91 	?>
    78 </outline>
    92 </outline>
    79 <?php
    93 	<?php
    80 endforeach; // $cats
    94 endforeach; // $cats
    81 ?>
    95 ?>
    82 </body>
    96 </body>
    83 </opml>
    97 </opml>