Ticket #6393: wp_export_import_links_with_cats_new.patch
File wp_export_import_links_with_cats_new.patch, 4.0 KB (added by , 17 years ago) |
---|
-
wp-admin/link-import.php
100 100 101 101 include_once('link-parse-opml.php'); 102 102 103 $blogroll_cats = get_terms('link_category', 'get=all'); 104 foreach ($blogroll_cats as $category){ 105 $blogroll_categories[$category->name] = $category->term_id; 106 } 107 103 108 $link_count = count($names); 104 109 for ( $i = 0; $i < $link_count; $i++ ) { 110 111 if ( !$cat_id = is_term( $link_categories[$i], 'link_category' ) ) { 112 $cat_id = wp_insert_term( $link_categories[$i], 'link_category' ); 113 $cat_id = $cat_id['term_id']; 114 $blogroll_categories[$link_categories[$i]] = $cat_id; //adding item to an array of link_cateories from database 115 } 116 else { 117 $cat_id = (int) $blogroll_categories[$link_categories[$i]]; 118 } 119 105 120 if ('Last' == substr($titles[$i], 0, 4)) 106 121 $titles[$i] = ''; 107 122 if ( 'http' == substr($titles[$i], 0, 4) ) 108 123 $titles[$i] = ''; 109 $link = array( 'link_url' => $urls[$i], 'link_name' => $wpdb->escape($names[$i]), 'link_category' => array($cat_id), 'link_description' => $wpdb->escape($descriptions[$i]), 'link_owner' => $user_ID, 'link_rss' => $feeds[$i] );124 $link = array( 'link_url' => $urls[$i], 'link_name' => $wpdb->escape($names[$i]), 'link_category' => array($cat_id), 'link_description' => $wpdb->escape($descriptions[$i]), 'link_owner' => $user_ID, 'link_rss' => $feeds[$i], 'link_target' => $targets[$i]); 110 125 wp_insert_link($link); 111 126 echo sprintf('<p>'.__('Inserted <strong>%s</strong>').'</p>', $names[$i]); 112 127 } -
wp-admin/link-parse-opml.php
9 9 'TITLE' => 'link_name', 10 10 'TARGET' => 'link_target', 11 11 'DESCRIPTION' => 'link_description', 12 'XMLURL' => 'link_rss' 12 'XMLURL' => 'link_rss', 13 'CATEGORY' => 'category' 13 14 ); 14 15 15 16 $map = $opml_map; … … 20 21 **/ 21 22 function startElement($parser, $tagName, $attrs) { 22 23 global $updated_timestamp, $all_links, $map; 23 global $names, $urls, $targets, $descriptions, $feeds ;24 global $names, $urls, $targets, $descriptions, $feeds, $link_categories; 24 25 25 26 if ($tagName == 'OUTLINE') { 26 27 foreach (array_keys($map) as $key) { … … 37 38 $targets[] = $link_target; 38 39 $feeds[] = $link_rss; 39 40 $descriptions[] = $link_description; 41 $link_categories[] = $category; 40 42 } // end if outline 41 43 } 42 44 -
wp-links-opml.php
26 26 if (empty ($link_cat)) 27 27 $cats = get_categories("type=link&hierarchical=0"); 28 28 else 29 $cats = get_categories('type=link&hierarchical=0&include='.$link_cat);29 $cats = array (get_category($link_cat)); 30 30 31 31 foreach ((array) $cats as $cat) { 32 32 $catname = apply_filters('link_category', $cat->name); 33 33 34 ?>35 <outline type="category" title="<?php echo attribute_escape($catname); ?>">36 <?php37 38 34 $bookmarks = get_bookmarks("category={$cat->term_id}"); 35 39 36 foreach ((array) $bookmarks as $bookmark) { 40 37 $title = attribute_escape(apply_filters('link_title', $bookmark->link_name)); 38 $description = attribute_escape(apply_filters('link_description', $bookmark->link_description)); 39 $target = $bookmark->link_target; 41 40 ?> 42 <outline text="<?php echo $title; ?>" type="link" xmlUrl="<?php echo attribute_escape($bookmark->link_rss); ?>" htmlUrl="<?php echo attribute_escape($bookmark->link_url); ?>" updated="<?php if ('0000-00-00 00:00:00' != $bookmark->link_updated) echo $bookmark->link_updated; ?>" />41 <outline text="<?php echo $title; ?>" type="link" url="<?php echo attribute_escape($bookmark->link_url); ?>" category="<?php echo $catname; ?>" description="<?php echo $description; ?>" target="<?php echo $target; ?>" /> 43 42 <?php 44 43 45 44 } 46 ?>47 </outline>48 <?php49 50 45 } 51 46 ?> 52 47 </body>