[ Index ]
 

Code source de WordPress 2.1.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/wp-admin/ -> export.php (source)

   1  <?php
   2  require_once  ('admin.php');
   3  $title = __('Export');
   4  $parent_file = 'edit.php';
   5  
   6  if ( isset( $_GET['download'] ) )
   7      export_wp();
   8  
   9  require_once  ('admin-header.php');
  10  ?>
  11  
  12  <div class="wrap">
  13  <h2><?php _e('Export'); ?></h2>
  14  <div class="narrow">
  15  <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
  16  <p><?php _e('This format, which we call WordPress eXtended RSS or WXR, will contain your posts, comments, custom fields, and categories.'); ?></p>
  17  <p><?php _e('Once you&#8217;ve saved the download file, you can use the Import function on another WordPress blog to import this blog.'); ?></p>
  18  <form action="" method="get">
  19  <h3><?php _e('Optional options'); ?></h3>
  20  
  21  <table>
  22  <tr>
  23  <th><?php _e('Restrict Author:'); ?></th>
  24  <td>
  25  <select name="author">
  26  <option value="all" selected="selected"><?php _e('All'); ?></option>
  27  <?php
  28  $authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" );  
  29  foreach ( $authors as $id ) {
  30      $o = get_userdata( $id );
  31      echo "<option value='$o->ID'>$o->display_name</option>";
  32  }
  33  ?>
  34  </select>
  35  </td>
  36  </tr>
  37  </table>
  38  <p class="submit"><input type="submit" name="submit" value="<?php _e('Download Export File'); ?> &raquo;" />
  39  <input type="hidden" name="download" value="true" />
  40  </p>
  41  </form>
  42  </div>
  43  </div>
  44  
  45  <?php
  46  
  47  function export_wp() {
  48  global $wpdb, $posts, $post;
  49  
  50  $filename = 'wordpress.' . date('Y-m-d') . '.xml';
  51  
  52  header('Content-Description: File Transfer');
  53  header("Content-Disposition: attachment; filename=$filename");
  54  header('Content-type: text/xml; charset=' . get_option('blog_charset'), true);
  55  
  56  $where = '';
  57  if ( isset( $_GET['author'] ) && $_GET['author'] != 'all' ) {
  58      $author_id = (int) $_GET['author'];
  59      $where = " WHERE post_author = '$author_id' ";
  60  }
  61  
  62  $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
  63  
  64  $categories = (array) $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (category_id = cat_id) LEFT JOIN $wpdb->posts ON (post_id <=> id) $where GROUP BY cat_id");
  65  
  66  function wxr_missing_parents($categories) {
  67      if ( !is_array($categories) || empty($categories) )
  68          return array();
  69  
  70      foreach ( $categories as $category )
  71          $parents[$category->cat_ID] = $category->category_parent;
  72  
  73      $parents = array_unique(array_diff($parents, array_keys($parents)));
  74  
  75      if ( $zero = array_search('0', $parents) )
  76          unset($parents[$zero]);
  77  
  78      return $parents;
  79  }
  80  
  81  while ( $parents = wxr_missing_parents($categories) ) {
  82      $found_parents = $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories WHERE cat_ID IN (" . join(', ', $parents) . ")");
  83      if ( is_array($found_parents) && count($found_parents) )
  84          $categories = array_merge($categories, $found_parents);
  85      else
  86          break;
  87  }
  88  
  89  // Put them in order to be inserted with no child going before its parent
  90  $pass = 0;
  91  $passes = 1000 + count($categories);
  92  while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
  93      if ( $cat->category_parent == 0 || isset($cats[$cat->category_parent]) ) {
  94          $cats[$cat->cat_ID] = $cat;
  95      } else {
  96          $categories[] = $cat;
  97      }
  98  }
  99  unset($categories);
 100  
 101  function wxr_cdata($str) {
 102      if ( seems_utf8($str) == false )
 103          $str = utf8_encode($str);
 104  
 105      // $str = ent2ncr(wp_specialchars($str));
 106  
 107      $str = "<![CDATA[$str" . ( ( substr($str, -1) == ']' ) ? ' ' : '') . "]]>";
 108  
 109      return $str;
 110  }
 111  
 112  function wxr_cat_name($c) {
 113      if ( empty($c->cat_name) )
 114          return;
 115  
 116      echo '<wp:cat_name>' . wxr_cdata($c->cat_name) . '</wp:cat_name>';
 117  }
 118  
 119  function wxr_category_description($c) {
 120      if ( empty($c->category_description) )
 121          return;
 122  
 123      echo '<wp:category_description>' . wxr_cdata($c->category_description) . '</wp:category_description>';
 124  }
 125  ?>
 126  <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. -->
 127  <!-- It contains information about your blog's posts, comments, and categories. -->
 128  <!-- You may use this file to transfer that content from one site to another. -->
 129  <!-- This file is not intended to serve as a complete backup of your blog. -->
 130  
 131  <!-- To import this information into a WordPress blog follow these steps. -->
 132  <!-- 1. Log into that blog as an administrator. -->
 133  <!-- 2. Go to Manage: Import in the blog's admin panels. -->
 134  <!-- 3. Choose "WordPress" from the list. -->
 135  <!-- 4. Upload this file using the form provided on that page. -->
 136  <!-- 5. You will first be asked to map the authors in this export file to users -->
 137  <!--    on the blog.  For each author, you may choose to map to an -->
 138  <!--    existing user on the blog or to create a new user -->
 139  <!-- 6. WordPress will then import each of the posts, comments, and categories -->
 140  <!--    contained in this file into your blog -->
 141  
 142  <!-- generator="wordpress/<?php bloginfo_rss('version') ?>" created="<?php echo date('Y-m-d H:m'); ?>"-->
 143  <rss version="2.0"
 144      xmlns:content="http://purl.org/rss/1.0/modules/content/"
 145      xmlns:wfw="http://wellformedweb.org/CommentAPI/"
 146      xmlns:dc="http://purl.org/dc/elements/1.1/"
 147      xmlns:wp="http://wordpress.org/export/1.0/"
 148  >
 149  
 150  <channel>
 151      <title><?php bloginfo_rss('name'); ?></title>
 152      <link><?php bloginfo_rss('url') ?></link>
 153      <description><?php bloginfo_rss("description") ?></description>
 154      <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
 155      <generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
 156      <language><?php echo get_option('rss_language'); ?></language>
 157  <?php if ( $cats ) : foreach ( $cats as $c ) : ?>
 158      <wp:category><wp:category_nicename><?php echo $c->category_nicename; ?></wp:category_nicename><wp:category_parent><?php echo $c->category_parent ? $cats[$c->category_parent]->cat_name : ''; ?></wp:category_parent><wp:posts_private><?php echo $c->posts_private ? '1' : '0'; ?></wp:posts_private><wp:links_private><?php echo $c->links_private ? '1' : '0'; ?></wp:links_private><?php wxr_cat_name($c); ?><?php wxr_category_description($c); ?></wp:category>
 159  <?php endforeach; endif; ?>
 160      <?php do_action('rss2_head'); ?>
 161      <?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>
 162  <item>
 163  <title><?php the_title_rss() ?></title>
 164  <link><?php permalink_single_rss() ?></link>
 165  <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
 166  <dc:creator><?php the_author() ?></dc:creator>
 167  <?php the_category_rss() ?>
 168  
 169  <guid isPermaLink="false"><?php the_guid(); ?></guid>
 170  <description></description>
 171  <content:encoded><![CDATA[<?php echo $post->post_content ?>]]></content:encoded>
 172  <wp:post_id><?php echo $post->ID; ?></wp:post_id>
 173  <wp:post_date><?php echo $post->post_date; ?></wp:post_date>
 174  <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
 175  <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
 176  <wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
 177  <wp:post_name><?php echo $post->post_name; ?></wp:post_name>
 178  <wp:status><?php echo $post->post_status; ?></wp:status>
 179  <wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
 180  <wp:post_type><?php echo $post->post_type; ?></wp:post_type>
 181  <?php
 182  $postmeta = $wpdb->get_results("SELECT * FROM $wpdb->postmeta WHERE post_id = $post->ID");
 183  if ( $postmeta ) {
 184  ?>
 185  <?php foreach( $postmeta as $meta ) { ?>
 186  <wp:postmeta>
 187  <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
 188  <wp:meta_value><?Php echo $meta->meta_value; ?></wp:meta_value>
 189  </wp:postmeta>
 190  <?php } ?>
 191  <?php } ?>
 192  <?php
 193  $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = $post->ID");
 194  if ( $comments ) { foreach ( $comments as $c ) { ?>
 195  <wp:comment>
 196  <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
 197  <wp:comment_author><?php echo $c->comment_author; ?></wp:comment_author>
 198  <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
 199  <wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url>
 200  <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
 201  <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
 202  <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
 203  <wp:comment_content><?php echo $c->comment_content; ?></wp:comment_content>
 204  <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
 205  <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
 206  <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
 207  </wp:comment>
 208  <?php } } ?>
 209      </item>
 210  <?php } } ?>
 211  </channel>
 212  </rss>
 213  <?php
 214      die();
 215  }
 216  
 217  include  ('admin-footer.php');
 218  ?>


Généré le : Fri Mar 30 19:41:27 2007 par Balluche grâce à PHPXref 0.7